dongpa3109 2017-06-27 06:07
浏览 223

MySQL查询不返回任何结果

I know that this type of question has been asked before. But it most probably is something to do with the query itself. right now the whole thing is php tagged. and this is where i think I am going wrong. This is a perfectly legit phpmyadmin query and returns desired results:

SELECT sm.stockid, (SELECT price FROM prices WHERE stockid = sm.stockid AND typeabbrev = 'RT') AS RT, (SELECT price FROM prices WHERE stockid = sm.stockid AND typeabbrev = 'TR') AS TR, (SELECT price FROM prices WHERE stockid = sm.stockid AND typeabbrev = 'FL') AS FL, (SELECT price FROM prices WHERE stockid = sm.stockid AND typeabbrev = 'DE') AS DE FROM stockmaster sm

This is the format I have it in:

$query = "SELECT sm.stockid, (SELECT price FROM prices WHERE stockid = sm.stockid AND typeabbrev = 'RT') AS RT, (SELECT price FROM prices WHERE stockid = sm.stockid AND typeabbrev = 'TR') AS TR, (SELECT price FROM prices WHERE stockid = sm.stockid AND typeabbrev = 'FL') AS FL, (SELECT price FROM prices WHERE stockid = sm.stockid AND typeabbrev = 'DE') AS DE FROM stockmaster sm";

This block of code though prints nothing:

$result = mysqli_query($db, $query);    
$recordCount = mysqli_num_rows($result);
echo $recordCount; 

But in phpmyadmin the query returns the following:

desired results

I probably need to escape the single quotes or redo my php tagging. Thank you in advance for any help.

  • 写回答

5条回答 默认 最新

  • dragonhong641016 2017-06-27 06:22
    关注

    You should fetch data using while loop.Try this:

    $result = mysqli_query($db, $query);    
    $recordCount = mysqli_num_rows($result);
    if($recordCount > 0){
       while($row = mysqli_fetch_array($result)){
          print_r($row);
       }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度