dongshanxiao7328 2012-10-05 15:39
浏览 9
已采纳

mysql_fetch_assoc崩溃了php代码[关闭]

I need to change of not my PHP code and I ran into some problem (please notice that I usually code in Java and haven't develop in PHP for quite few years).

I have the following peace of code:

   $sql = "SELECT id_class FROM  events e join event_to_class ec on e.id = ec.id_event WHERE e.id = ".$r['id']."  and ec.id_evaluator = 8 and (".$stepNumbers.")";
   $mirekClassesForEvent = mysql_query($sql) or trigger_error(mysql_error().$sql); 
   if (!$mirekClassesForEvent) {
      echo "Could not successfully run query from DB: " . mysql_error();
      exit;
   }               
   $mirekClasses = array();        
   if (mysql_num_rows($mirekClassesForEvent) > 0 ) {
      while($row = mysql_fetch_assoc($mirekClassesForEvent) {
           array_push($mirekClasses, $row['id_class'];
      }
   } 

the select statement looks like this:

SELECT id_class FROM events e join event_to_class ec on e.id = ec.id_event WHERE e.id = 1 and ec.id_evaluator = 8 and (e.id_step=4 OR e.id_step=5 OR e.id_step=6)

when I run it in the MySQL DB to runs fine and returns one row of data with

id_class=27

.

However when I run the code above my php script crashes (it doesn't even show any error messages - even when I try to use mysql_error() function)

From my debuggin it looks like the problem is in the while statement, but I don't understand what could be the problem.

  • 写回答

2条回答 默认 最新

  • dongshuo1856 2012-10-05 15:41
    关注

    You are missing a ) at the end of the while line, and another on the array_push line. If you are seeing no error, you probably have error reporting off. Using an editor with syntax highlighting would help you find this kind of error, as they usually include highlighting of mismatched parentheses.

    Note that you could simplify your query a little by using IN:

    ... and e.id_step IN (4,5,6)
    

    Or BETWEEN:

    ... and e.id_step BETWEEN 4 AND 6
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作