mysql 语句显示表或消息
我的数据库中有一个订单表,一旦用户登录他的帐户,他/她就可以查看他/她以前的订单。
我有以下代码:
<?php
$result = mysql_query("SELECT * FROM `order` WHERE username = '". $_SESSION['username']."' ")
or die(mysql_error()); ;
echo "<table border='0'><table border width=100%><tr><th>Product</th><th>Quantity</th><th>Price</th><th>Date</th>";
while($info = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $info['name']. "</td>";
echo "<td>" . $info['quantity']. "</td>";
echo "<td>" . $info['price']. "</td>";
echo "<td>" . $info['date']. "</td>";
}
echo "</tr>";
echo "</table>";
?>
我使用什么 mysql 语句来显示消息“您还没有订购任何东西”而不是空白表?
谢谢
I have an order table in my database and once a user logs into his account, he/she can view his/her previous orders.
I have the following code for it:
<?php
$result = mysql_query("SELECT * FROM `order` WHERE username = '". $_SESSION['username']."' ")
or die(mysql_error()); ;
echo "<table border='0'><table border width=100%><tr><th>Product</th><th>Quantity</th><th>Price</th><th>Date</th>";
while($info = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $info['name']. "</td>";
echo "<td>" . $info['quantity']. "</td>";
echo "<td>" . $info['price']. "</td>";
echo "<td>" . $info['date']. "</td>";
}
echo "</tr>";
echo "</table>";
?>
what mysql statement do i use to show a message 'you have not ordered anything yet' instead of a blank table?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
mysql_num_rows() 计算语句中的结果数
:此外,您可能希望在
while
循环内移动倒数第二行 (echo "";
)这样 HTML 就可以正确输出了。You can count the number of results in your statement using
mysql_num_rows()
:Also, you probably want to move the second to last line (
echo "</tr>";
) inside yourwhile
loop so the HTML is outputted correctly.您可以使用
mysql_num_rows()
获取结果集中的行数。You could use
mysql_num_rows()
to get the number of rows in the resultset.使用 mysql_num_rows
Use mysql_num_rows