【发布时间】:2012-07-25 10:22:53
【问题描述】:
我正在尝试构建客户电子商务后端。我以前做过很多次这样的事情,并不认为自己对 php 和 mysql 是“新手”,但我被卡住了,不知道哪里出了问题。
我只想在特定位置显示 mysql 行的内容(使用“WHERE”命令)。
但是当我加载页面时,内容部分(在表格中)是空的。该位置的表格中肯定有内容,页面上的所有其他内容都显示,但实际的 customerResults 除外。
这是我的代码:
<head>
<title>Customer Summary</title>
<?php
session_start();
require 'database_connect.php';
$customerTable = "customer";
if(isset($_GET['customer_click'])){
$customerId = $_GET['customer_click'];
}
?>
</head>
<h3>Customer <?php echo"$customerId"?></h3>
<table align="center" width="600px">
<tr>
<td><a href="index.php">Summary</a></td>
<td><a href="personal.php">Personal</a></td>
<td><a href="billing.php">Billing</a></td>
<td><a href="order_history.php">Order History</a></td>
</tr>
</table>
<table align="center" width="400px">
<tr>
<?php
$customerSelect = "SELECT * FROM $customerTable WHERE id = '$customerId' ";
$customerResult = mysql_query($customerSelect);
if (!$customerResult){
echo "No results, but why?!?!? </br/>";
}
if (mysql_num_rows($customerResult)==0){
echo "Results are empty...but why!?!?!";
}
while ($customerData = mysql_fetch_assoc($customerResult)){
echo $customerData['id'];
echo $customerData['email'];
}
?>
</tr>
</table>
我可能忽略了一些简单的事情,但我真的想不通
【问题讨论】:
-
对我来说足够新:)。欢迎来到堆栈溢出!请不要将
mysql_*函数用于新代码。它们不再维护,社区已经开始deprecation process。看到red box?相反,您应该了解prepared statements 并使用PDO 或MySQLi。如果您不能决定,this article 将帮助您选择。如果你想学习,here is good PDO tutorial. -
那么您遇到了什么错误?你试过什么?
-
您确认您没有收到任何 Mysql 错误吗?当
mysql_query返回FALSE结果时,可能意味着没有行,或者查询没有成功。 -
运行时会发生什么? PHP 错误、SQL 错误、空结果...
-
您确定 $customerTable 以及更重要的是 $customerId 变量设置正确吗?