Jump to content

Retrieve Unique Values


ririe44

Recommended Posts

Hey everyone...

 

I would like to be able to retrieve the unique values of a column of a mysql table to be a list of values in my html <select> code...  for example:

 

ColA

----

red

blue

green

red

 

I want it to return... red, blue, green... and make them part of my drop down menu in my form.  Can you help me?

 

 

Link to comment
https://forums.phpfreaks.com/topic/156365-retrieve-unique-values/
Share on other sites


<?php
$con = mysql_connect("localhost","name","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM table");

while($row = mysql_fetch_array($result))
  {
  echo '<option value="'.$row['color'].'">'.$row['colorname'].'</option>';
  }

mysql_close($con);
?>

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.