你是怎么传的?
<?php
print_r($_POST);
?>
<form action="" method="post">
<input type="checkbox" name="name_and_price[foodname][]" value='aa'/>1
<input type="checkbox" name="name_and_price[foodname][]" value='bb'/>2
<input type="checkbox" name="name_and_price[foodprice][]" value='1'/>3
<input type="checkbox" name="name_and_price[foodprice][]" value='3'/>4
<input type="submit" value="提交"/>
</form>
提交后显示
Array
(
[name_and_price] => Array
(
[foodname] => Array
(
[0] => aa
[1] => bb
) [foodprice] => Array
(
[0] => 1
[1] => 3
) ))
<?php
print_r($_POST);
?>
<form action="" method="post">
<input type="checkbox" name="name_and_price[foodname][]" value='aa'/>1
<input type="checkbox" name="name_and_price[foodname][]" value='bb'/>2
<input type="checkbox" name="name_and_price[foodprice][]" value='1'/>3
<input type="checkbox" name="name_and_price[foodprice][]" value='3'/>4
<input type="submit" value="提交"/>
</form>
提交后显示
Array
(
[name_and_price] => Array
(
[foodname] => Array
(
[0] => aa
[1] => bb
) [foodprice] => Array
(
[0] => 1
[1] => 3
) ))
<form name="form1" method="post" action="totalcost.php">中间定义了一个二维数组:
$name_and_price["foodname"][] = 'aa';
$name_and_price["foodname"][] = 'bb';
$name_and_price["foodname"][] = 'cc';
$name_and_price["foodprice"][] = 1;
$name_and_price["foodprice"][] = 3;
$name_and_price["foodprice"][] = 5;
$name_and_price["foodprice"][] = 7;
</form>我在这个页面用echo $name_and_price["foodprice"][1] ;可正常输出值
但在totalcost.php页面(即按了按钮后转到的页面)中的语句:
echo $_POST[$food_and_price["foodname"][1]]; 却不能显示值?怎么回事?
<form name="form1" method="post" action="totalcost.php"><?
$db_connect = mysql_connect("localhost","root","");
mysql_select_db("fireshop", $db_connect);
$char_sql = "SELECT * FROM foodtable";
$p_sql = mysql_query($char_sql);
echo "<table border = 1>";
echo "<tr>"."<th>"."菜名"."</th>"."<th>"."单价"."</th>"."<th>"."份数"."</th>"."<th>"."菜名"."</th>"."<th>"."单价"."</th>"."<th>"."份数"."</th>"."<th>"."菜名"."</th>"."<th>"."单价"."</th>"."<th>"."份数"."</th>"."</tr>"."<br>";
$index = 0;
$foodnumber = 0;
while($row = mysql_fetch_array($p_sql, MYSQL_NUM))
{ if(($index)%3==0)
echo "<tr>";
echo "<th>";
echo $row[0];
echo "</th>";
echo "<th>";
echo $row[1];
echo "</th>";
$food_and_price[] = $row[0];
$food_and_price[] = $row[1];//你是说这个数组应该放在哪里?
echo "<th>";
echo "<input type = text size = 3 name = textfield$foodnumber>";//textfield$foodnumber也是必须传的
echo "</th>";
$index++;
$foodnumber++;
if(($index%3)==0)
echo "</tr>";
}
echo "</table>";
mysql_close($db_connect);
?>
<input type="hidden" name="price[]" value="$row[1]">