Hi I am trying to convert this snippet of code which is a drop down that pulls the values from a mysql database. I would like to create a loop and display these items as radio buttons. I've tried a few different ways without the greatest results. Any help would be greatly appreciated. Thanks.

<select name="doc_type">
<? 
print_option($doc_type, '', 'All Doc Types');
  foreach ($kb_page_info['doc_type']['valid_values'] as $valid_doc_type) {
print_option($doc_type, $valid_doc_type, $valid_doc_type);
}
?>
</select>

    Uh... well considering you haven't shown us what the print_option() function does or where $kb_page_info['doc_type']['valid_values'] is ever defined (or what data it might contain), there's not much we can offer without more information.

      bradgrafelman;10967939 wrote:

      Uh... well considering you haven't shown us what the print_option() function does or where $kb_page_info['doc_type']['valid_values'] is ever defined (or what data it might contain), there's not much we can offer without more information.

      Oooops that might have been the hint to resolve this. I totally didn't even check that function.

      function print_option($variable, $value, $display, $id=NULL)
      {
      	$display = html_value($display);
      	$selected = ($variable == $value) ? " selected=\"selected\"" : '';
      	$value = form_value($value);
      	$id = ($id) ? "id=\"${id}\" " : '';
      	echo "<option ${id}value=\"{$value}\"{$selected}>{$display}</option>\n";
      }

        Well we still need the rest of the information, e.g. what does $kb_page_info['doc_type']['valid_values'] look like ([man]var_dump/man will give a pretty accurate description) and what is the current non-working output of the script?

          bradgrafelman;10967944 wrote:

          Well we still need the rest of the information, e.g. what does $kb_page_info['doc_type']['valid_values'] look like ([man]var_dump/man will give a pretty accurate description) and what is the current non-working output of the script?

          I'm still looking to track it down. One thing leads to another page and then another page and another page. ugh

            bradgrafelman;10967944 wrote:

            Well we still need the rest of the information, e.g. what does $kb_page_info['doc_type']['valid_values'] look like ([man]var_dump/man will give a pretty accurate description) and what is the current non-working output of the script?

            Ok var_dump shows the array

            array(7) { [0]=>  string(3) "FAQ" [1]=>  string(10) "Help Sheet" [2]=>  string(18) "Marketing Resource" [3]=>  string(13) "Promotion Kit" [4]=>  string(23) "Trainer / Teacher Guide" [5]=>  string(8) "Tutorial" [6]=>  string(22) "Reference / User Guide" } 

            Sorry for the scrolling text 🙁

            I'm just not able to convert this to radio buttons so when one is selected it can perform the same way is if you had selected it in a select. Hope that made sense.

              I fixed the initial problem but now I'm stuck with this function. No matter what I try I can't edit the option values (last line) to hold the users selections when the form is submitted. Could there be somewhere I'm not looking if its not done in here?

              I'm basically trying to add something like

               <?php if (($_REQUEST[$value]) == $value) echo 'selected'; ?>
              function print_option($variable, $value, $display, $id=NULL)
              {
              	$display = html_value($display);
              	$selected = ($variable == $value) ? " selected=\"selected\"" : '';
              	$value = form_value($value);
              	$id = ($id) ? "id=\"${id}\" " : '';
              	echo "<option ${id}value=\"{$value}\"{$selected}>{$display}</option>\n";
              }
              

              Any ideas? :queasy:

                Write a Reply...