I've been trying to use PHP to display all the results from MySql NOTES table that match specific NAME in QUOTES table. Objective being I want to display all the COMMENTS listed under each specific NAME.
QUOTES table columns: ID / NAME / EMAIL / PRICE
NOTES table columns: ID / NAME / AGENT / DATE / COMMENTS
Here is the MySql code I'm using:
mysql_select_db($database_dbConnect, $dbConnect);
$query_rsquotes = "SELECT * FROM quotes ORDER BY `id` DESC";
$rsquotes = mysql_query($query_rsquotes, $dbConnect) or die(mysql_error());
$row_rsquotes = mysql_fetch_assoc($rsquotes);
$totalRows_rsquotes = mysql_num_rows($rsquotes);
mysql_select_db($database_dbConnect, $dbConnect);
$query_rsnotes = "SELECT quotes.*, notes.* FROM quotes INNER JOIN notes ON quotes.name = notes.name ORDER BY notes.date DESC";
$rsnotes = mysql_query($query_rsnotes, $dbConnect) or die(mysql_error());
$row_rsnotes = mysql_fetch_assoc($rsnotes);
$totalRows_rsnotes = mysql_num_rows($rsnotes);
Then to display results:
<?php do { ?>
<?php echo $row_rsquotes['name']; ?>
<?php echo $row_rsquotes['email']; ?>
<?php
if ($row_rsquotes['name'] == $row_rsnotes['name']) {
do {
if ($row_rsquotes['name'] == $row_rsnotes['name']) {
echo "<div class='agentNotes'><p><strong>DATE: </strong><span class='meta-date'>" . $row_rsnotes['date'] . "</span></p><p><strong>AGENT:</strong> " . $row_rsnotes['agent'] . "</p><p><strong>AGENT NOTES:</strong> " . $row_rsnotes['comments'] . "</p></div>";
}
} while ($row_rsnotes = mysql_fetch_assoc($rsnotes));
}
?>
<?php } while ($row_rsquotes = mysql_fetch_assoc($rsquotes)); ?>
It loops through and displays the matching records for that particular NAME, but then when it gets to the next NAME, it does not display the matching COMMENTS. What am I doing wrong?