Jump to content

Looping problem, getting too many results


mullberrymae

Recommended Posts

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();



?>

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'";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.