Jump to content

[SOLVED] generating dropdowns beside radios dependant on that radio


aebstract

Recommended Posts

$content .= "<form action=\"/prices/addmaterial/$var2/\" method=\"post\">";



/* ------------------------- GENERATE GRADES OF MATERIAL ------------------------- */
$result = mysql_query("SELECT DISTINCT grade FROM `materials` WHERE material='$dropdown'") or DIE(mysql_error());
while($r = mysql_fetch_array($result))
{
  $id_p = $r['id'];
  $grade = $r['grade'];
  $content .= "$grade<input type=\"radio\" name=\"grade\" value=\"$grade\" />";



  $content .= '<select name="$grade"><option value="">----------</option>';
  /* ------------------------- GENERATE SIZES OF MATERIAL ------------------------- */
  $result2 = mysql_query("SELECT * FROM `materials` WHERE material='$dropdown' && grade='$grade' ORDER BY `size_d` ASC") or DIE(mysql_error());
  while($r2 = mysql_fetch_array($result2))
  {
    $id_p = $r2['id'];
    $size = $r2['size'];
    $content .= "<option value=\"{$id_p}\">{$size}\"</option>\n";
  }
$content .= '</select><br />';



}


$content .= "Length: <input type=\"text\" size=\"5\" name=\"length\" value=\"\" /><br />
<input type=\"submit\" name=\"submit2\" value=\"Add Material\" />
";

$content .= '</form>';

 

 

Okay, time for the fun of explaining this stuff. I'm going to use two pieces of material for my example, two pieces of bearing stock. One is 303 stainless and the other is 304 stainless. In the database I have a table with this information: id - material - size - price - size_d - grade

 

The grade is the 303 and 304, I am generating a unique radio button for each type of grade, so in this situation there are two radio buttons. Beside the radios I need to generate a drop down menu with the sizes for all the specific material of that grade. The code I posted does this fine, what I am stuck on is when I choose the first radio button that is generated and choose a size in the drop down and hit submit, I can display my grade choice but not my size choice. If I choose the last radio and a size, it'll show both. I'm sure it has something to do with how I am naming the drop down menus but I am not too sure of what to do at this point. I will keep working on it and keep this post updated. Thanks

Eh, I don't know why that is what it was showing before, but now I get this:

 

Array ( [grade] => 303 SS [303_SS] => 1 [304_SS] => [length] => [submit2] => Add Material )

 

 

It's putting an underscore in my drop down name 'grade', is that the problem? Is there anyway for me to prevent that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.