dounanyin3179 2010-01-27 14:35
浏览 68
已采纳

MySQL查询在phpmyadmin中工作,但PHP结果集中没有返回任何行

I have the following MySQL query:

SELECT SQL_CALC_FOUND_ROWS p.*
FROM product AS p
LEFT JOIN productCategory AS c ON FIND_IN_SET(c.id, REPLACE(TRIM(p.categories), ' ',','))
WHERE (
    c.id IS NULL
    OR c.status = 'D'
    OR p.categories IS NULL
    OR TRIM(p.categories) = ''
)
AND p.deprecated = 'N'
LIMIT 0,30

This query is to pick up products which:

  • Has something set in p.categories column, but the row on the productCategory table does not exist
  • Have a productCategory row, but the status on the productCategory row is set to 'D'
  • Have nothing set in the p.categories column

p.categories is a row with space separated numeric values representing ids on the productCategory table. Not the best design, granted but I have been given this task, so need a way of doing it.

In the PHP code, this query is executed directly afterwards:

SELECT FOUND_ROWS() as count

When executed from phpmyadmin, I get thousands of rows returned and when I append the second query, I get a count value of the correct number of rows. When I execute the same first query through mysqli_query(), I get no rows at all returned and the following query returns a count of 1.

Both phpmyadmin and my PHP code are connecting to the same database.

Can anyone see what is going wrong?!

Update:

I only want the first 30 rows returned because there could be a huge total number, in the subsequent query, I should get a count of what that total would be, hence SQL_CALC_FOUND_ROWS after the first SELECT.

  • 写回答

2条回答 默认 最新

  • doucai5315 2010-01-28 12:02
    关注

    For some reason, changing the first line of the query:

    SELECT SQL_CALC_FOUND_ROWS p.*
    

    To:

    SELECT SQL_CALC_FOUND_ROWS p.id
    

    And then looping through the results getting the data I needed from each row in separate queries got the result I was after.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?