mullberrymae Posted April 20, 2011 Share Posted April 20, 2011 I am getting repeat results, need help to stop this $sqlgb ="SELECT * FROM `guestbook`JOIN `obituaries` ON (guestbook.obits_id = '$id') "; $results=mysql_query($sqlgb) or die("Error: ". mysql_error(). " with query ". $sqlgb); $num = mysql_num_rows($results); if ($num > 0 ) { $i=0; while ($i < $num) { $id = mysql_result($results,$i,"id"); $obits_id = mysql_result($results, $i, "obits_id"); $name = mysql_result($results,$i,"name"); $email = mysql_result($results,$i,"email"); $message = mysql_result($results, $i, "message"); $postdate = mysql_result($results,$i,"postdate"); //$deceased = mysql_result($results, $i "fname"); $date = convertdate($postdate); ?> <p class="ptext">Message From: <a href="mailto:<?php echo $email; ?>"><?php echo $name; ?></a></p> <p class="ptext"><?php echo $postdate; ?></p> <p class="ptext"><?php echo $message; ?></p> <p> <div align="center"><h2> <a href="gbview.php?id=<?php echo($id); ?>">View Guestbook</a> | <a href="gbpost.php?id=<?php echo($id); ?>">Sign the Guestbook</a></h2></div> </p> <?php ++$i; } } else { echo($results['obituaries.fname']); } mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/234214-looping-problem-getting-too-many-results/ Share on other sites More sharing options...
The Little Guy Posted April 20, 2011 Share Posted April 20, 2011 when doing a join, you need to join table a column on table b column These two queries may return different results: $sqlgb ="SELECT * FROM `guestbook`JOIN `obituaries` ON (guestbook.obits_id = obituaries.obits_id and guestbook.obits_id = '$id') "; or $sqlgb ="SELECT * FROM `guestbook`JOIN `obituaries` ON (guestbook.obits_id = obituaries.obits_id) where guestbook.obits_id = '$id'"; Link to comment https://forums.phpfreaks.com/topic/234214-looping-problem-getting-too-many-results/#findComment-1203838 Share on other sites More sharing options...
mullberrymae Posted April 20, 2011 Author Share Posted April 20, 2011 Thanks so much ! Solved. Link to comment https://forums.phpfreaks.com/topic/234214-looping-problem-getting-too-many-results/#findComment-1203840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.