Hi,
I have been trying to populate an option box from database using some code I found in the forum but cannot get it to work, I keep getting error unexpected ; in line 6
The mysql database is jos_chronoforms_data_enterGifts I want to populate an option box with the column data gift_description about 35 rows in total.
Any help would be appreciated
Irvin Metcalf
I have been trying to populate an option box from database using some code I found in the forum but cannot get it to work, I keep getting error unexpected ; in line 6
The mysql database is jos_chronoforms_data_enterGifts I want to populate an option box with the column data gift_description about 35 rows in total.
Any help would be appreciated
Irvin Metcalf
<?php
$db =& JFactory::getDBO();
$query = 'SELECT * FROM ' . $db->gift_description('#__chronofroms_data_enterGifts');
$db->setQuery($query);
if ($gift_description =& $db->loadObjectList();) {
echo "<select name="gift_description">";
foreach ($descriptions as $gift_description) {
echo "<option value='" . $gift_description->descriptions . "'></option>";
}
echo "</select>";
} else {
echo "No Gifts Available";
}
?>
I'm no php whiz, but shouldn't it be:
?
echo "<option value=".$gift_description->descriptions."></option>";
?
Hi irvingmetcalf,
There are a few things wrong with the code,not least that the $db->gift_subsctiption method doesn't exist. Please try this version
Note: I've changed this to set the record id as the option value.
Bob
@Mark, actually the single quotes are required so that you end up with value='some description'
There are a few things wrong with the code,not least that the $db->gift_subsctiption method doesn't exist. Please try this version
<?php
$db =& JFactory::getDBO();
$query = "
SELECT `id`, `description`
FROM `#__chronofroms_data_enterGifts` ;
";
$db->setQuery($query);
$gift_description =& $db->loadObjectList();
if ( count($gift_description) ) {
echo "<select name="gift_description">";
foreach ( $gift_description as $g ) {
echo "<option value='{$g->id}'>{$g->description}</option>";
}
echo "</select>";
} else {
echo "No Gifts Available";
}
?>
Note: I've changed this to set the record id as the option value.
Bob
@Mark, actually the single quotes are required so that you end up with value='some description'
This topic is locked and no more replies can be posted.