简单查询不从数据库中提取

时间:2015-09-07 16:08:02

标签: php

我无法弄明白,这不是错误,但是当我试图回应查询的结果时:

  echo "SELECT * FROM `active_customers` WHERE `cus_email`='".$k."' AND `cus_product`='".$_GET['product']."'" . "<br />";
  $q = mysql_query("SELECT * FROM `active_customers` WHERE `cus_email`='".$k."' AND `cus_product`='".$_GET['product']."'");
  $a = mysql_fetch_array($r);
  $n = mysql_num_rows($q);
  echo "Number of rows:" . $n;
  echo $a['cus_id'];
  echo $a['cus_email'];

帖子数量返回正确的数字,即1,这些值 $ a [&#39; cus_id&#39;]; $ a [&#39; cus_email& #39;]; 根本没有通过,我甚至在phpmyadmin中做了一个mysql查询,它在那里工作。

谁能看到我做错了什么?

1 个答案:

答案 0 :(得分:0)

正确的代码可以是

echo "SELECT * FROM `active_customers` WHERE `cus_email`='".$k."' AND `cus_product`='".$_GET['product']."'" . "<br />";
$q = mysql_query("SELECT * FROM `active_customers` WHERE `cus_email`='".$k."' AND `cus_product`='".$_GET['product']."'");
$n = mysql_num_rows($q);
echo "Number of rows:" . $n;
while($row = mysql_fetch_array($q, MYSQL_ASSOC)){
  echo $row['cus_id'];
  echo $row['cus_email'];
}

虽然我建议将mysqli或PDO用于sql数据库