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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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