My task is essentially to make a dropdown list, using the <option>
tag, out of a table in a database. To simplify it, I have created a MySQL procedure that will output the value based on its ranking in the table. The procedure has a parameter id since the output is passed on to the <option>
tag. Hence, each <option>
tag will fetch the single row outputted by the procedure based on its id in the database.
I know it's not the ideal implementation, though, but I'm working through it so I can even improve it once the basics are working. With my current implementation, no data is fetched from the database any more after the loop is run once. Here is the php code:
$counter=1;
while ($exec2>0)
{
$res = mysql_query("CALL PROMOSTAFF_RANKING($counter);");
$exec3 = mysql_fetch_array($res);
$fname = $exec3[0];
$lname = $exec3[1];
echo '<option value="';echo $fname; echo ' '; echo $lname;echo '" >';echo $fname; echo ' '; echo $lname; echo'</option>';
$exec2--;
$counter++;
}
In the html, only the first dropdown option displays correctly, while the second and third (since there should be 3 options) are blank. I have outputted values of $counter and $exec2 for the second and third options, and they have the correct values to be able to run the procedure. However, I guess after the first iteration of the loop, no value is fetched to $fname and $lname.
Can anybody enlighten me on this? I would love to learn more and improve the codes with your inputs. Thanks!