user959443 user959443 - 1 year ago 97
PHP Question

dynamic populate a select input from mysql

Hi I am trying to populate an entire Drop down list with MySQL but I cant get it to work, can you please help?

My code:

$database=& JFactory::getDBO();

$database->setQuery('SELECT training_id,training,trainingDate FROM training ');

$result = $database->loadObjectList();

echo '<select name="whatever">';
while($row = mysql_fetch_array($result)) {
echo '<option value="$row[training_id" />';

echo '</select>';

Answer Source

Your echo string doesn't allow for embedded variables because you are using single quotes instead of double quotes.

Implement this echo instead:

echo '<option value="' . $row["training_id"] . '" />';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download