I have two tables in the database, one for weblog entries and one for comments;
I have written the following code but think that this is possibly the wrong way to go about it? This is just me testing at the moment, but would like some advice
Should i be putting a seperate query within the while loop? is that bad practice? Or is the way im going just stupid...A little direction thanks...
Oh, please ignore variable names, like i say proof of concept really
I have written the following code but think that this is possibly the wrong way to go about it? This is just me testing at the moment, but would like some advice
$query = "SELECT * FROM entry";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
$entry_id = $row['entry_id'];
$entry = $row['content'];
$author = $row['author'];
echo "<h4>$author wrote the following weblog entry:</h4><p>$entry</p>";
$sub_query = "SELECT * FROM comments WHERE entry_id = '$entry_id'";
$result2 = mysql_query($sub_query);
while ($row2 = mysql_fetch_assoc($result2))
{
$comment = $row2['content'];
$author2 = $row2['author'];
$email = $row2['email'];
echo "<br>$author2 / $email left the following comment:<br><p>$comment</p>";
}
}
Should i be putting a seperate query within the while loop? is that bad practice? Or is the way im going just stupid...A little direction thanks...
Oh, please ignore variable names, like i say proof of concept really