Jump to content

[SOLVED] [Q]How do i prevent ouputting the same value in a while loop?


DieterDaems

Recommended Posts

For now this is all i got.

Because i have no idea, how to prevent outputting the same value.

And still continueing the loop.

Can anyone help me, or point me in the right direction?

 

with friendly greetings, Dieter

 

               $myDb->connect();
		$sql  = "SELECT * FROM 
		`winelist`, `winemakers`
		 WHERE (`winelist`.`winemakerid` = `winemakers`.`id`)
		 ORDER BY 
		 winecountry, winetype, winename_sub, wineyear ";
		 $query = mysql_query($sql) or die("Query failed: " . mysql_error());
		 $result = mysql_fetch_array($query);
	$myDb->close();

			echo "<h3 class='menuheader expandable'>Per Winemaker</h3>";
  				echo "<ul class='categoryitems'>";
  			while ($result = mysql_fetch_array($query)){
  							
  				$makername = htmlentities($result['makername']);
			echo "<li><a href='wines.php?winemaker='$makername'>$makername</a></li>";
  			}
  				echo "</ul>";

Use DISTINCT or GROUP to make your life easier.

This would be a slight mod of your SQL statement

$sql  = "SELECT * FROM
         `winelist`, `winemakers`
          WHERE (`winelist`.`winemakerid` = `winemakers`.`id`)
          GROUP BY 
          fieldName 
          ORDER BY
          winecountry, winetype, winename_sub, wineyear ";

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.