I wrote a sweet little php function to populate drop down lists.
and it works 98% of what I want it to do. the only thing is that I feed it this Query for the $SQL varible.
$SQL = "`PrimeID` = '".$ClientName."' ORDER BY `EquipName` ASC";
What it creates is a drop down list that looks like this...
[Computer]
T1
Office
T2
All
--------
What I would like it to look like is:
[Computer]
Office
T1
T2
All
--------
Both the Computer Option and All option are declared outside of the function call like this...
Anyone got any ideas? The ORDER BY command doesn't seem to have an effect...
Code:
function PopulateSQLDropDown($Table,$Field,$SQL,$Sel){
$Connection = mysql_connect("localhost","username","pass");
mysql_select_db ("dbname");
$sql = "SELECT * FROM `$Table` WHERE $SQL";
$Query = mysql_query($sql);
$i=0;
while (mysql_fetch_row($Query)){
$Result=mysql_result($Query,$i,$Field);
if($Result!=$PrevResult)
echo "<option value=\"".$Result."\"";
if($Result == $Sel)
echo "selected";
echo ">".$Result."</option><br>";
$i++;
$PrevResult=$Result;
}
mysql_close($Connection);
}
$SQL = "`PrimeID` = '".$ClientName."' ORDER BY `EquipName` ASC";
What it creates is a drop down list that looks like this...
[Computer]
T1
Office
T2
All
--------
What I would like it to look like is:
[Computer]
Office
T1
T2
All
--------
Both the Computer Option and All option are declared outside of the function call like this...
Code:
echo '<select name="Comp" onchange="this.form.submit()" selected='.$Comp.'>';
echo "<option value=\"\">Computer</option><br>";
$SQL = "`PrimeID` = '".$ClientName."' ORDER BY `EquipName` ASC";
PopulateDropdown("Equipment","EquipName",$SQL,"");
echo '<option value="All">All</option><br>';
echo '</select>';
Anyone got any ideas? The ORDER BY command doesn't seem to have an effect...