Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to populate a selection box without repeating item with same name. 1

Status
Not open for further replies.

phn737

Technical User
Nov 4, 2002
31
0
0
US
Hi,

I am trying to populate a selection box without having the item with same name (sting) repeate in the selection box. Is this possible?

Thanks.

 
Yes, it is possible.

However, without knowing more about the source of the data what will go into the select, I cannot advise you further. ______________________________________________________________________
TANSTAAFL!
 
Well, I am not sure but let me try to explain.
So I have a table (t1) with ~100 rows and in one of the column (c3)contains one of the following value (blank,type1,type2,type3...). So I would like the selection box to have the name of each item only once. What I have so far will populate all the items in the box.

[...]
// create SQL statement
$sql = "SELECT c3 FROM t1
ORDER BY c3 ASC";
// execute SQL query and get result
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {
$deviceid = $row["c3"];
$option_block .= &quot;<OPTION value=\&quot;$c3\&quot;>$c3</OPTION>&quot;;
}

Is this better?
 
Ahhhh!

Try:

$sql = &quot;SELECT DISTINCT c3 FROM t1 ORDER BY c3 ASC&quot;; ______________________________________________________________________
TANSTAAFL!
 
sleipnir214,
Thank you. Yes, that is what I needed. You just have all the answer :) . And I was about to attempt to use 'in_array' function to walk through and check for repeating string when I have to idea if in_array is appropriate for the task and no very strong on coding.

As someone once posted, if you have a doubt/question, ask.

phn737
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top