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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?