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?
$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?