Radio Box with DB possible ?

BigStef 24 May, 2011
Hi !
I have try your tutorial for dropbox using DB. It worked well and i had no problems... I wanted to test this function with the radio box. But my knowledge in coding is so pour that I couldn't have a result. What I need is some radio box from a DB (for example : Radio1=17h Radio2=20h) and my customer can erase this hours on table (more easy for him)...

For memory this is the code for the dropdown :
<div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">
      Postes</label>
    <select class="cf_inputbox validate-selection"
        id="articles" size="1" name="articles">
      <option value=''>--?--</option>
<?php
if (!$mainframe->isSite() ) {return;}
$db =& JFactory::getDBO();
$query = "
  SELECT `id`, `title`
    FROM `#__content`
    WHERE `sectionid` = 1
      AND `state` = 1 ;
";
$db->setQuery($query);
$options = $db->loadAssocList();
foreach ( $options as $o ) {
  echo "<option value='".$o[id]."'>".$o[title]."</option>";
}
?>
    </select>
  </div>
  <div class="cfclear"> </div>
</div>

If anyone could help me, that would be really great ! Thanks by advance...
GreyHead 26 May, 2011
Hi BigStef,

Here's a versioj of the article code re-written for radio buttons.
<?php
if (!$mainframe->isSite() ) {return;}
$db =& JFactory::getDBO();
$query = "
  SELECT `id`, `title`
    FROM `#__content`
    WHERE `sectionid` = 1
      AND `state` = 1 ;
";
$db->setQuery($query);
$radio_buttons = $db->loadObjectList();
$i = 0;
foreach ( $radio_buttons as $b ) {
  echo "<input value='{$b->id}' title='' class='radio' id='article{$i}' name="article" type="radio" /><label for='article{$i}' class="radio_label">{$b->title}</label>";
  $i++
}
$radio_buttons = implode("<br />\n", $radio_buttons);
?>
. . .
<div class="form_item">
  <div class="form_element cf_radiobutton">
    <label class="cf_label" style="width: 150px;">Articles</label>
    <div class="float_left">
<?php echo $radio_buttons; ?>
    </div>
  </div>
  <div class="cfclear"> </div>
</div>
Not tested and will need debugging!

Bob
BigStef 19 Jun, 2011
Hi Bob,
Thanks a lot for your answer...
I will try it and keep the forum informed about that...
Thanks again -)
This topic is locked and no more replies can be posted.