[SOLVED] if select, save id and title to db...?

Ritchie 14 Nov, 2011
Hi Guys,

Below you see a working dropdown selectbox voor CF v4. As the code is know it only saves the "TITLE" in a DB FIELD (producten).
But i also wan't to save the "ID" in a DB FIELD when selecting a product and not only the "TITLE".

How do i solve this?

Regards
Ritchie

<select size="1" type="select" name="producten">
<option value="">-------- producten --------</option>
<?php
$db =& JFactory::getDBO();
$query = "SELECT id,title FROM lw0bd_faqbook_items ORDER BY title";
$db->setQuery( $query );
$option = $db->loadObjectList();
foreach ( $option as $o) {
   echo "<option value='{$o->title}' >{$o->title}</option>";
}
?>
Ritchie 15 Nov, 2011
Is this the way? Bob?

<?php
$db =& JFactory::getDBO();
$id = JRequest::getVar('producten', '', 'get');
if ( $id) {
  $query = "
    Select title from lw0bd_faqbook_items
        WHERE `id` = '".$id."' ";
}
Ritchie 16 Nov, 2011
This is solved by great help from Bob.

the code that solved my problem:

echo "<option value=\"{$o->id}|{$o->title}\" >{$o->title}</option>";
This topic is locked and no more replies can be posted.