哎呀对不起,我忘记改了。在此代码中,它将显示 cakename 列表。
<?php
$sql="SELECT * FROM $tbl_name ORDER BY c_id ASC";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
$c_id=$rows['c_id']; // idnumber of cake
$cakename=$rows['cakename']; //this is the name of cake
$options.="<OPTION VALUE=\"$c_id\">$cakename</OPTION>"; //it will list all the cake
// close while loop
}
?>
<select name="order_id">
<option value=0>Select Cake:<?php echo $options; ?>
</select>
而这个,当用户选择了 cake1.it 将显示细节,价格和图片。这是我的问题。我想结合所有的代码。我不知道如何显示图片。
<html>
<form action="current_file.php" method="POST">
<select name="order_id" id="order_id" onChange="this.form.submit()">
<option value="">Select Cake:</options>
<option value="1">cake1</options>
<option value="2">cake2</options>
<option value="3">cake3</options>
</select>
</form>
<?php
$order_id=$_POST['order_id'];
if (!empty($order_id)){
$sql="SELECT * FROM $tbl_name WHERE c_id = $order_id";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
$price=$rows['price'];
$details=$rows['details'];
$picture=$rows['picture'];
// close while loop
}
echo $details;
echo $price;
}//close if statement
?>
是的,所有的代码都在工作。但我只想成为一个。明白了吗?像这样但不工作:
<?php
$order_id=$_POST['order_id'];
if (!empty($order_id)){
$sql="SELECT * FROM $tbl_name WHERE c_id = $order_id";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
$price=$rows['price'];
$details=$rows['details'];
$picture=$rows['picture'];
$c_id=$rows['c_id']; // idnumber of cake
$cakename=$rows['cakename']; //this is the name of cake
$options.="<OPTION VALUE=\"$c_id\">$cakename</OPTION>"; //it will list all the cake
// close while loop
}
?>
<form action="current_file.php" method="POST">
<select name="order_id" id="order_id" onChange="this.form.submit()">
<option value=0>Select Cake:<?php echo $options; ?>
</select>
<?php
echo $details;
echo $price;
echo $picture;
?>
</form>