It is not displaying anything right now drop some input thanks. <?php $sql = "SELECT * FROM comments "; $sql .= " WHERE appetizers_id= '$id '"; $sql .= " ORDER BY created ASC"; echo '<div id="comments"> <?php foreach($sql as $comment): ?> <div class="comment" style="margin-bottom: 2em;"> <div class="author"> <?php echo htmlentities($fullname); ?> wrote: </div> <div class="body"> <?php echo strip_tags($cons); ?> </div> <div class="body"> <?php echo strip_tags( $pros); ?> </div> <div class="meta-info" style="font-size: 0.8em;"> <?php echo datetime_to_text($created); ?> </div> </div> <?php endforeach; ?> <?php if(empty($sql)) { echo "No Comments."; } ?> </div>'; ?> PHP:
check that id should not be empty and then print the query and manualy run it in the mysql and see the results .
First you need to query the SQL statement, which it seems you didn't. Also you need to rewrite your HTML/PHP code which is all mixed up together.
I have done what you told me guys but still is not working. any other suggestion? <?php $sql = "SELECT * FROM comments "; $sql .= " WHERE appetizers_id= '$id '"; $sql .= " ORDER BY created ASC"; $result = mysql_query($sql) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { echo '<div id="comments"> <?php foreach($sql as $comment): ?> <div class="comment" style="margin-bottom: 2em;"> <div class="author"> <?php echo htmlentities($fullname); ?> wrote: </div> <div class="body"> <?php echo strip_tags($cons); ?> </div> <div class="body"> <?php echo strip_tags( $pros); ?> </div> <div class="meta-info" style="font-size: 0.8em;"> <?php echo datetime_to_text($created); ?> </div> </div> <?php endforeach; ?> <?php if(empty($sql)) { echo "No Comments."; } ?> </div>';} ?> PHP:
Did you not read my other post on your other thread You are running the query now but you need to loop through it as i've shown, your foreach loop should be using $result as this is the resource you need to loop through, $sql is simply a String.
thank you wd_2k6 Right now it is displaying and inserting. I will clean the <?php open and closing tags ?> so it is not so confusing. Next i will be working in a rating system, it will be alot of fun..
This is the loop printing all the message working perfectly but now it keep repeating the same message everytime the page is refreshed in firefox is there a way to avoid that? by redirecting the page to avoid repetition? The following message appears when I refresh the browser: How can it be avoided so it just save the data and then continue without repeating the previous message over? this is the while loop and the mysql query statement to call the comments from the database $rResult = mysql_query( sprintf( "SELECT * FROM comments WHERE shoename_id = %d ORDER BY created ASC", $id ) ); if(mysql_num_rows($rResult) > 0) { while($aComment = mysql_fetch_assoc($rResult)) { printf( ' <div class="comment" style="margin-bottom: 2em;"> <div class="author"> <strong>%s</strong> wrote: </div> <div class="body"> <strong>Pros:</strong>%s </div> <div class="body"> <strong>Cons:</strong>%s </div> <div class="meta-info" style="font-size: 0.8em;"> <strong>Time:</strong>%s </div> </div> ', $aComment['fullname'], $aComment['pros'], $aComment['cons'], $aComment['created'] ); } } PHP: