JackJack Posted April 3, 2006 Share Posted April 3, 2006 I wish to create something that would have the data from another page which was a drop down box/menu.Example:[code]echo "Choose select a <b>motor</b> for<br> your robot: ";echo "<select name='part1'>";echo "<option value='null'>Select a Motor</option>"; $romotor = mysql_query("select * from `parts` where `owner` = '$stat[id]' and `slot` = 'Motor'"); while ($partuno = mysql_fetch_array($romotor)) {echo "<option value='$partuno[id]'>$partuno[name] </option>";}echo "</select>";echo "<br><br>Now add a <b>shell</b> to<br> your robot: ";echo "<select name='part2'>";echo "<option value='null'>Select a Shell</option>"; $roshell = mysql_query("select * from `parts` where `owner` = '$stat[id]' and `slot` = 'Shell'"); while ($partdeux = mysql_fetch_array($roshell)) {echo "<option value='$partdeux[id]'>$partdeux[name]</option>";}echo "</select>";[/code]Next Page[code] mysql_query("insert into bots (motor, shell) values('???','??????')")[/code]Thank You For Your HelpJJ Quote Link to comment Share on other sites More sharing options...
Barand Posted April 3, 2006 Share Posted April 3, 2006 You seemed to be repeating chunks of code so I put the option list build into a function. For clarity I also renamed the <SELECTS> as "motor" and "shell".[code]function getOptions($id, $type) { $str = "<OPTION value=''> - Select a $type -</OPTION>\n"; $res = mysql_query("select id, name from `parts` where `owner` = '$id' and `slot` = '$type'"); while (list($id, $name) = mtsql_fetch_row($res)) { $str .= "<OPTION value='$id'> $name</OPTION>\n"; } return $str;}echo "<FORM action='nextpage.php' method='post'>\n";echo "<p>Choose select a <b>motor</b> for<br> your robot:</p> ";echo "<select name='motor'>";echo getOptions($stat['id'], 'Motor');echo "</select>\n";echo "<p>Now add a <b>shell</b> to<br> your robot:</p>";echo "<select name='shell'>";echo getOptions($stat['id'], 'Shell');echo "</select>\n";echo "<p><INPUT TYPE='SUBMIT' name='submit' value='Submit'></p>\n"echo "</FORM>\n";[/code]:: nextpage.php ::[code] $motor = $_POST['motor']; $shell = $_POST['shell']; mysql_query ("INSERT INTO bots (motor, shell) VALUES ('$motor', '$shell')");[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.