I have these two functions to fill a dropdown list.
function fillcombo($table,$colname)
{
$list="";
$sql="select $colname from $table order by $colname";
$Rs = setRs($sql); // Get data from database using setRs function
foreach($Rs as $opt) {
$list .='<option value="'.$opt[$colname] .'">'. $opt[$colname] .'</option>';
}
unset($opt);
return $list;
}
//---------------------------------------------------------------------------
function setRs($sql){
include ('connect.php');
mysqli_select_db($conn,"MyDB" ); //Select database
$Rs = mysqli_query($conn,$sql) or die(mysqli_error($conn)); //Run Query
return $Rs; //Return recordset
$conn->close();
}
// This $Recordset has 93 rows as in my database. But the foreach loops only 5 times.
return $list yields the following html.
<option value=""></option><option value=""></option><option value=""></option><option value=""></option><option value=""></option>
On my PC it works fine and the select list is filled with all the 93 values. Any help will be greatly appreciated..Thanks
Aucun commentaire:
Enregistrer un commentaire