0

我有一个正在查询的数据库并将结果回显到屏幕上。这些行一直回显到从数据库返回的数组中获取信息的位置。我似乎无法找出为什么省略数据。

case 'search':
echo "<br>";
echo "searching: ".$firstname;
echo "<br>";



$sqlsearch="SELECT * FROM Customer WHERE firstname='$firstname'";


$data = mysql_query($conndb, $sqlsearch);

//$row = mysql_fetch_array($results);

while($row = mysql_fetch_array($data));
{
echo "firstname: ".$row['firstname']."<br>";
echo "lastname: ".$row['lastname']."<br>";  
echo "phone: ".$row['phone']."<br>";
echo "address: ".$row['address']."<br>";
echo "city: ".$row['city']."<br>";
echo "state: ".$row['state']."<br>";
echo "zip: ".$row['zip']."<br>";
echo $sqlsearch;
break;
}

echo "<br>";
echo "seaching 2";
mysql_close($condb);
break;

如果我运行这个输出,搜索我在数据库中输入的名字为“Jon”的用户,所以我知道连接正在工作,至少输入看起来像这样:

searching: Jon
firstname: 
lastname: 
phone: 
address: 
city: 
state: 
zip: 
SELECT * FROM Customer WHERE firstname='Jon'

Customer 是一个表,其中包含以下字段 firstname、lastname、phone、address、city、state、zip。这些是列的确切名称和大小写。我没有将任何一个字段列为主键,因为我没有那样设置它。

4

1 回答 1

0

Not that I should be promoting mysql_ functions since they're deprecated, but have you tried switching the parameters?

mysql_query($conndb, $sqlsearch);

should be

mysql_query($sqlsearch, $conndb);

according to these docs:

http://php.net/manual/en/function.mysql-query.php

Please note the enormous warning at the top of that page and how it suggests using mysqli or PDO

于 2013-09-26T02:21:57.330 回答