<?php
mysql_connect("host", "user", "pw") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
$sql = "SELECT machine_id FROM machines";
$result = mysql_query($sql);
echo "<form action='results_send.php' method='post' >";
echo "<select name='machine_id'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['machine_id'] . "'>" . $row['machine_id'] . "</option>";
}
echo "</select></form>";
echo '<input type="submit" value="Submit">';
$machine = $_POST['machine_id'];
var_dump($machine);
?>
返回:
<form action='results_send.php' method='post' ><select name='machine_id'><option value='2011 Honda'>2011 Honda</option><option value='1999 Toyota'>1999 Toyota</option><option value='1999 Honda'>1999 Honda</option><option value='1999 Honda'>1999 Honda</option><option value='2013 Toyota'>2013 Toyota</option><option value='2012 Ford'>2012 Ford</option><option value='2012 Ford'>2012 Ford</option><option value='2012 Ford'>2012 Ford</option><option value='2012 Ford'>2012 Ford</option></select></form><input type="submit" value="Submit">NULL
所有这些都在同一个文档中:results_send.php
我只尝试了几天的 php/mysql —— 非常感谢耐心。