Php 数据Id没有显示这是为什么?
这是我的代码,为什么price的数据显示而ID不显示?请帮忙Php 数据Id没有显示这是为什么?,php,mysql,database,arrays,Php,Mysql,Database,Arrays,这是我的代码,为什么price的数据显示而ID不显示?请帮忙 <?php include"Connection.php"; $dTime = time(); $myValue = $_REQUEST['dValue']; echo "The time is: {$dTime}<br/> The choice is {$myValue} "; $sql = "Select * from product where NAME = '{$myValue}'"; $result =
<?php
include"Connection.php";
$dTime = time();
$myValue = $_REQUEST['dValue'];
echo "The time is: {$dTime}<br/>
The choice is {$myValue} ";
$sql = "Select * from product where NAME = '{$myValue}'";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
$price = $row['PRICE'];
$id = $row['ID'];
echo "PHP $price";
echo "$id";
$sql2 ="INSERT INTO `starbucks`.`order_details` (`ID`, `ORDER_ID`, `PRODUCT_ID`, `QTY`) VALUES ('2', '1', '$id', '1');";
$result2 = mysql_query($sql2);
?>
不要忘记大括号,否则只执行一行代码
while ($row = mysql_fetch_assoc($result)){
$price = $row['PRICE'];
$id = $row['ID'];
echo 'PHP ', $price; // do not use variable concatenation or double quotes if you can
echo $id; // no need to wrap a variable with quotes for printing it
}
别忘了,否则你会很容易受到攻击
您没有任何花括号来描述while循环,因此它只运行行
$price=$row['price']代码>用于每行。尝试:
while ($row = mysql_fetch_assoc($result))
{
$price = $row['PRICE'];
$id = $row['ID'];
echo "PHP $price";
echo "$id";
}
为什么不在while循环中使用大括号
while ($row = mysql_fetch_assoc($result))
在这之后它将只执行一行,而不是第二行在$row上尝试一个var\u dump
。如果不查看“产品”表的结构,我们无法回答此问题。您能否在数据库上运行产品中的显示列?编辑:可能是花括号,而不是数据结构。您好。你到底为什么要回显“$id”代码>和非echo$id代码>。请去学习一些PHP基础知识。
while ($row = mysql_fetch_assoc($result))