Jump to content

comments function


m00nz00mer

Recommended Posts

hey, im making a little system that allows users to add comments to a page.. ive got it all working and it adds the info the the db however say i have for example 'comment1' showing if the user adds a new comment 'comment2' it replaces 'coment1'. im wanting to display all the comments ( comment1 and 2 ).

 

I think its to do with selecting one row...? how could this be adjusted to select more than one row?

 

$reviewedByQuery =

 

"SELECT ..... query here";

 

$reviewedByQueryResult = mysql_query($reviewedByQuery);

$num_rows = mysql_num_rows($reviewedByQueryResult);

 

if($num_rows>0 && $num_rows_date>0 && $num_rows_comment>0){

 

$commentText = mysql_result($reviewCommentQueryResults, 0);

$reviewDate = mysql_result($reviewDateQueryResults, 0);

$reviewedBy = mysql_result($reviewedByQueryResult, 0);

 

//Display Comment

echo "Comments: <div class='detailTextGrey'>".$commentText." </div><br/>";

 

//Display Date

echo "Date of Review: <div class='detailTextGrey'>".$reviewDate." </div>";

 

//Display Review Query

echo "Reviewed by: <div class='detailTextGrey'>".$reviewedBy." </div><br/><br/>";

} else {

echo "No reviews have been posted...";

}

Link to comment
Share on other sites

hey, thanks for the reply, ive tried using the while loop like so... but its displaying a never ending list of the same commend, name and date?

 

$reviewedByQueryResult = mysql_query($reviewedByQuery);

$num_rows = mysql_num_rows($reviewedByQueryResult);

 

if($num_rows>0 && $num_rows_date>0 && $num_rows_comment>0){

while ($comment = mysql_fetch_row($reviewedByQueryResult)) {

 

$commentText = mysql_result($reviewCommentQueryResults, 0);

$reviewDate = mysql_result($reviewDateQueryResults, 0);

$reviewedBy = mysql_result($reviewedByQueryResult, 0);

 

//Display Comment

echo "Comments: <div class='detailTextGrey'>".$commentText." </div><br/>";

 

//Display Date

echo "Date of Review: <div class='detailTextGrey'>".$reviewDate." </div>";

 

//Display Review Query

echo "Reviewed by: <div class='detailTextGrey'>".$reviewedBy." </div><br/><br/>";

}

} else {

echo "No reviews have been posted...";

}

 

Link to comment
Share on other sites

Hey thanks for the advice, im trying to use the array now however im getting Notice: Undefined offset: 3 2 and 1. Does anyone know why this is happening? thanks again.

 

if($num_rows_comment>0){

while ($comment = mysql_fetch_array($reviewedByQueryResult)) {

 

list ($comBookISBN, $comUserID, $comReviewDate, $comReviewText) = $comment;

 

//Display Review Query

echo "Reviewed by: <div class='detailTextGrey'>".$comReviewText." </div><br/><br/>";

}

} else {

echo "No reviews have been posted...";

}

 

?>

Link to comment
Share on other sites

Hey,

 

You need to follow this kind of logic

 

$query = mysql_query("SELECT field1, field2 FROM table")

if (mysql_num_rows > 0) {

         while ($comment = mysql_fetch_array($query)) {
         
         //Display Comment
         echo $comment['field1'];
         echo $comment['field2'];
         
         }

}

 

I think you need to read up on loops and the mysql_fetch_array function. I think you are trying to over-complicate your code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.