[英]What am I doing wrong with his php mysql
What my intention is to put a table on my website containg some fields from a datbase which contain an ID 我的目的是在我的网站上放置一个表格,其中包含来自datbase的一些包含ID的字段
$con = mysqli_connect('hostname','username','password','dbname');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
$sql="SELECT * FROM Orders WHERE `Student UID` = '".$id."'";
$result = mysqli_query($con,$sql);
echo
echo "<table><tr><th>Product</th><th>Cost</th></tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['MenuItemName'] . "</td>";
echo "<td>" . $row['Price'] . "</td>";
echo "</tr>";
}
echo "</table>";
At the moment when I am running this, I am jut getting a table like this 在我运行此命令的那一刻,我正在伸出一张这样的桌子
+---------+-------+
| Product | Price |
+---------+-------+
My database looks like this 我的数据库看起来像这样
+--------------+-------+-------------+
| MenuItemName | Price | Student UID |
+--------------+-------+-------------+
| Foo | 99 | 12345 |
| Foo2 | 11 | 11111 |
| Foo2 | 11 | 12345 |
+--------------+-------+-------------+
What am I doing wrong with this? 我在做什么错呢?
Try changing this line: 尝试更改此行:
$sql="SELECT * FROM Orders WHERE 'Student UID' = '".$id."'";
to: 至:
$sql="SELECT * FROM Orders WHERE `Student UID` = '".$id."'";
Shout solve your issue. 喊解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.