I would like to display User Comments - on a given Article - from my database, but am unsure of how to do this being a newbie?!
The comments should be displayed below the Article to which they pertain in a format like this…
[COLOR=“SeaGreen”]---------------------
By Larry Miller
8:05 a.m. on Sept 2, 2011
That was an interesting article!
By Paula W.
7:35 p.m. on Aug 29, 2011
Not sure I agree entirely, but some valid points…
[/COLOR]
I am using Prepared Statements, and this is what I have so far…
// Build Comments Query
$q = 'SELECT m.first_name, c.created_on, c.body, c.status
FROM member AS m
INNER JOIN comment AS c
ON m.id = c.member_id
WHERE article_id=?';
// Prepare statement.
$stmt = mysqli_prepare($dbc, $q);
// Bind variable.
mysqli_stmt_bind_param($stmt, 'i', $articleID);
// Execute query.
mysqli_stmt_execute($stmt);
// Store result-set.
mysqli_stmt_store_result($stmt);
// Check for Comments Record.
if (mysqli_stmt_num_rows($stmt)==1){
// Comment in Database.
$commentExists = TRUE;
// Bind result-set to variables.
mysqli_stmt_bind_result($stmt, $firstName, $createdOn, $body, $status);
// Fetch record.
mysqli_stmt_fetch($stmt);
}
I believe that mysqli_stmt_store_result($stmt); is what holds the results of my query, right?
Where exactly is that stored?
In some variable in memory?
So how can I iterate through the query results and output one record at a time in the format I described above?
Thanks,
Debbie