Page 1 of 1

Display only 1 row if repeats - quick problem

Posted: Thu Jul 06, 2006 3:33 pm
by waradmin
I seem to have blanked out and forgot how to make mysql display only 1 row if it repeats

For exmaple i have a database with values like name, and price

so it would be like: ITEM | PRICE

Car | 50000
Car | 42000
Bus | 34392
Car | 34021
Frog | 394

Then I made a list that display's items (a dropdown list), but I want it to only list Car on the item dropdown list ONCE. How do I adjust my code to display only 1 of each, and if a item name repeats only display it once.

Code: Select all

<form name="item_list" method="post" action="display.php?server=<?php echo "$server"; ?>">
<select name="item">
<?
#connect to MySQL
$rs = @mysql_connect( "localhost", "root", "----------" )
               	or die( "Could not connect to MySQL" );
#select the database
$rs = @mysql_select_db( "swg" ) 
		or die( "Could not select database" );
#create the SQL query
$sql = "select * from prices limit = 1";
#execute the query
$rs = @mysql_query( $sql ) 
		or die( "Could not execute SQL query" );
#loop through all records
while ( $row = mysql_fetch_array( $rs ) ) 
{
?>
  <option value="<?php echo $row["item"]; ?>"><?php echo $row["item"]; ?></option>
<?php } ?>
</select>
<input type="submit" name="Submit" value="Display Prices" />
</form>

Posted: Thu Jul 06, 2006 4:15 pm
by Christopher

Code: Select all

#create the SQL query
$sql = "select DISTINCT item,price from prices GROUP BY item";