简体   繁体   English

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

[英]Simple query not pulling from database

I cannot figure this out, it's not an error as such, but when i try to echo out the results of a query: 我无法弄清楚,这不是错误,但是当我尝试回显查询结果时:

  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'];

The number of posts is returning the correct number which is 1, these values $a['cus_id']; 帖子数返回的正确数字为1,即$ a ['cus_id']; and $a['cus_email']; $ a ['cus_email']; are not coming through at all, i even did a mysql query in phpmyadmin and it works there. 根本没有通过,我什至在phpmyadmin中做了一个mysql查询,并且在那里工作。

can anyone see what i have done wrong? 谁能看到我做错了什么?

correct code can be 正确的代码可以是

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'];
}

Although i would recommend using mysqli or PDO for sql databases 虽然我建议对mysql数据库使用mysqli或PDO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM