简体   繁体   English

mysql_num_rows返回0,但是phpMyAdmin中的相同查询返回结果

[英]mysql_num_rows returns 0, but the same query in phpMyAdmin return results

We have been working for a few hours on a serious problem. 我们已经在一个严重的问题上工作了几个小时。

We have the following code: 我们有以下代码:

mysql_connect("localhost","xxx","xxx") or die(mysql_error());
mysql_select_db("xxxe");

$q = "SELECT m.id, m.expired_date, u.email
     FROM jos_osemsc_member m, jos_osemsc_orders o, jos_users u
    WHERE o.order_id  = $orderID
   AND m.member_id = o.user_id
   AND u.id  = o.user_id";

$res = mysql_query($q);

if (!$res) {
  mail('xxx@xxx.com','test',mysql_error());
}

mail("xxx@xxx.com", "count",  mysql_num_rows($res));

We receive the "count" mail, but with "0" for result of mysql_num_rows. 我们收到“计数”邮件,但mysql_num_rows的结果为“ 0”。 If we send the query ($q) by e-mail, and execute it in phpMyAdmin, it works and we get one row resulted... 如果我们通过电子邮件发送查询($ q),并在phpMyAdmin中执行查询,那么它将起作用,并且会得到一行结果...

Any ideas ? 有任何想法吗 ?

Thanks for the help which will be VERY apperciated 感谢您的帮助,我们将非常感谢

用户xxx可能比您用于PMA的用户具有更多的限制性权限。

Try re-wording your query. 尝试重新措词您的查询。 I find LEFT JOINs much easier to comprehend and deal with. 我发现LEFT JOIN容易理解和处理。

SELECT m.id, m.expired_date, u.email
FROM jos_osemsc_orders AS o 
        LEFT JOIN jos_osemsc_member AS m ON (m.member_id = o.user_id) 
        LEFT JOIN jos_users AS u ON (u.id = o.user_id)
WHERE o.order_id  = $orderID;

If that doesn't work, reduce the query to just the orders table and make sure you get a result. 如果这不起作用,请将查询减少到仅orders表,并确保获得结果。 If that works add a table, etc... 如果可行,请添加表格,等等。

Also, I can see where there would be a problem if an order was placed by someone who was a user but not a member, or vice versa. 另外,我可以看到如果订单是由用户而非成员下达的,哪里会有问题,反之亦然。 However the left join style query would solve that problem. 但是,左联接样式查询将解决该问题。 Also, I edited the order of the tables in the query to make more sense. 另外,我在查询中编辑了表的顺序以使其更有意义。

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

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