Click to See Complete Forum and Search --> : Avoiding Repeats


Doc Thirst
08-10-2006, 12:28 PM
Quick question. I'm a table, which might have the same name repeated in several rows, to populate a select list:
$recordset = mssql_query ("select * from purchaseorder order by reqname", $handle);
while($arr = mssql_fetch_row($recordset))
{
$name = $arr[1];
echo "<option>$name";
}
As you can see, if there is more then one entry with the same name the select list will list the name several times.

I can't seem to think of a way to avoid this, but I know there must be a way.

For instance:
$recordset = mssql_query ("select * from purchaseorder order by reqname", $handle);
while($arr = mssql_fetch_row($recordset))
{
if($name == '%$totallist%')
{
$name = $arr[1];
echo "<option>$name";
}
$totalnames = "$totalnames $name";
}
Although I know my if statment is not valid, how do you pros do it?

NogDog
08-10-2006, 12:37 PM
$recordset = mssql_query ("SELECT DISTINCT reqname FROM purchaseorder ORDER BY reqname", $handle);
while($arr = mssql_fetch_row($recordset))
{
echo "<option>".$arr[0]."</option>\n";
}

Doc Thirst
08-10-2006, 12:45 PM
Ugg, soooo easy, I'm a tool. Thanks once again NogDog