I am building a custom blog. I am just learning PHP, but have managed to get my blog working okay. I am having an issue with the display of my categories. The categories display properly with the category title and the blog entry titles listed below, but my hyperlink to display the blog entries is not working properly. Instead of displaying the blog entries, my hyperlink is displaying the blog entry with the category ID and not the blog entry ID. I know this is propbably a really simple issue, but I just can't seem to correct it.
Below is my code to display the category title and blog entry with the hyperlink.
<?php
$sql = "SELECT * FROM categories";
$result = mysql_query($sql);
while ($row_cat = mysql_fetch_assoc($result)) {
echo '<h2 class="pSpaceBefore">' . $row_cat['cat'] . '</h2>'; //prints category heading
$sql = "SELECT subject, dateposted FROM entries WHERE cat_id = '" . $row_cat['id'] . "'"; //selects blog entries from database
$result_entries = mysql_query($sql);
$row_entries = mysql_num_rows($result_entries); //collects all rows in the result
echo "<ul>";
if($row_entries == 0){
echo "<li>no entries</li>"; //if no blog entries for the category print 'no entries'
}
else {
while ($row_entries = mysql_fetch_assoc($result_entries)) { //returns a row from a record set
echo "<li><a href = 'viewentry.php?id=" . $row_cat['id'] . "'>" . $row_entries['subject'] . "</a>" . " - " . date("F jS Y", strtotime($row_entries['dateposted'])) . "</li>"; //prints blog entries
}
echo "</ul>";
}
}
?>