m00nz00mer Posted February 21, 2008 Share Posted February 21, 2008 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 https://forums.phpfreaks.com/topic/92245-comments-function/ Share on other sites More sharing options...
m00nz00mer Posted February 21, 2008 Author Share Posted February 21, 2008 also is there any way to group them so that the data is returned like this... (comment1) name: (comment1) date : (comment1) etc (comment2) name: (comment2) date.. and so on Link to comment https://forums.phpfreaks.com/topic/92245-comments-function/#findComment-472558 Share on other sites More sharing options...
m00nz00mer Posted February 21, 2008 Author Share Posted February 21, 2008 anyone? Link to comment https://forums.phpfreaks.com/topic/92245-comments-function/#findComment-472609 Share on other sites More sharing options...
themistral Posted February 21, 2008 Share Posted February 21, 2008 You need to loop through the comments else if there is more than one else only 1 result will be shown. if($num_rows>0){ while ($comment = mysql_fetch_row($reviewedByQueryResult)) { // your info here } } else { // no comments made } Link to comment https://forums.phpfreaks.com/topic/92245-comments-function/#findComment-472617 Share on other sites More sharing options...
m00nz00mer Posted February 21, 2008 Author Share Posted February 21, 2008 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 https://forums.phpfreaks.com/topic/92245-comments-function/#findComment-472644 Share on other sites More sharing options...
m00nz00mer Posted February 21, 2008 Author Share Posted February 21, 2008 im losing my mind here, can someone help me Link to comment https://forums.phpfreaks.com/topic/92245-comments-function/#findComment-472686 Share on other sites More sharing options...
cooldude832 Posted February 21, 2008 Share Posted February 21, 2008 look at what the mysql_fetch_array function does your doing stuff competly wrong Link to comment https://forums.phpfreaks.com/topic/92245-comments-function/#findComment-472687 Share on other sites More sharing options...
m00nz00mer Posted February 21, 2008 Author Share Posted February 21, 2008 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 https://forums.phpfreaks.com/topic/92245-comments-function/#findComment-472716 Share on other sites More sharing options...
m00nz00mer Posted February 21, 2008 Author Share Posted February 21, 2008 anyone? Link to comment https://forums.phpfreaks.com/topic/92245-comments-function/#findComment-472734 Share on other sites More sharing options...
m00nz00mer Posted February 21, 2008 Author Share Posted February 21, 2008 bump bump Link to comment https://forums.phpfreaks.com/topic/92245-comments-function/#findComment-472807 Share on other sites More sharing options...
themistral Posted February 21, 2008 Share Posted February 21, 2008 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 https://forums.phpfreaks.com/topic/92245-comments-function/#findComment-472878 Share on other sites More sharing options...
m00nz00mer Posted February 21, 2008 Author Share Posted February 21, 2008 yeh i think i understand that however, the information that i need to select is quite complicated in terms of queries.. like using joins etc? as all the info required is not all in one table. Link to comment https://forums.phpfreaks.com/topic/92245-comments-function/#findComment-472902 Share on other sites More sharing options...
themistral Posted February 21, 2008 Share Posted February 21, 2008 The complexity of the query doesn't matter - but you need to reference the fields correctly and I think that could be where you're going wrong. Link to comment https://forums.phpfreaks.com/topic/92245-comments-function/#findComment-472995 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.