php - 显示一个用户的所有订单

标签 php mysql

<?php
include_once 'db.php';
$email = $_GET['email'];
$order_id = $_GET['order_id'];
$res=mysql_query("SELECT * FROM clients_buy WHERE email='$email'");
$row=mysql_fetch_array($res);
echo "<table border='1'>
<tr>
<th><center>order_id</center></th>
<th><center>item1</th>
<th><center>item2</th>
<th><center>item3</th>
<th><center>item4</th>
<th><center>item5</th>
</tr>";
while($row = mysql_fetch_assoc($res))
$row[] = $row;
echo "<tr>";
echo "<td><center>" . $row['user_id'] . "</center></td>";
echo "<td><center>" . $row['item1'] . "</center></td>";
echo "<td><center>" . $row['item2'] . "</center></td>";
echo "<td><center>" . $row['item3'] . "</center></td>";
echo "<td><center>" . $row['item4'] . "</center></td>";
echo "<td><center>" . $row['item5'] . "</center></td>";
echo '</tr>';
echo '</table>';
?>

我想在 php 页面中显示来自一个用户的所有订单。

最佳答案

正如 Sand 所说,请使用 mysqli 或 PDO。为什么你的 while 循环没有花括号?尽管尚未测试您的代码,但这似乎是一个错误的过程。 我会把它写成

while($row = mysql_fetch_assoc($res)){   
    echo "<tr>";
    echo "<td><center>" . $row['user_id'] . "</center></td>";
    echo "<td><center>" . $row['item1'] . "</center></td>";
    echo "<td><center>" . $row['item2'] . "</center></td>";
    echo "<td><center>" . $row['item3'] . "</center></td>";
    echo "<td><center>" . $row['item4'] . "</center></td>";
    echo "<td><center>" . $row['item5'] . "</center></td>";
    echo '</tr>';
}
echo '</table>';

关于php - 显示一个用户的所有订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46148924/

相关文章:

php - Laravel 8 中未定义的类型 Laravel\Sanctum\HasApiTokens

php - 尝试使用 PDO 对象时出错

php - 我无法在 mysql 上保存数据

c# - 使用 mysql 在 c# 中创建注册表单

mysql 存储过程返回 0 行受影响

php - 表单回显成功而不向数据库提交任何内容。我的流量控制有问题吗?

php - symfony2 中的自定义异常行为

php - 使用php从周数中获取月份值

php - 上传时在数据库中插入文件名而不是 CakePHP 中的数组

mysql - 当我使用数字类型选择 varchar 列时会发生什么?