mysqli_fetch_assoc()给出了意想不到的空值

时间:2015-12-07 12:05:12

标签: php mysql

这是我的SQL查询:

SELECT * FROM users,content 
LEFT OUTER JOIN articles ON ( 
  content.content_id = articles.content_id 
  AND content.content_type = 'article' ) 
LEFT OUTER JOIN projects ON ( 
  content.content_id = projects.content_id 
  AND content.content_type = 'project' )
LEFT OUTER JOIN videos ON ( 
  content.content_id = articles.content_id
  AND content.content_type = 'video' ) 
WHERE (content.content_id IN (128,414,399,616,259)) 
AND content.author_id = users.u_id 
order by FIELD(content.content_id,128,414,399,616,259)

当我在phpmyadmin上运行时,我正确地得到了结果但是当我通过执行mysqli_fetch_assoc()获取结果时,我得到content_id的空值。有人请帮帮我。提前致谢

编辑: 这是我的PHP代码

$query = "SELECT * 
      FROM   users,content
        LEFT OUTER JOIN articles 
                    ON ( content.content_id = articles.content_id 
                         AND content.content_type = 'article' ) 
        LEFT OUTER JOIN projects
                    ON ( content.content_id = projects.content_id 
                         AND content.content_type = 'project' ) 
        LEFT OUTER JOIN videos 
                    ON ( content.content_id = articles.content_id 
                         AND content.content_type = 'video' ) 
      WHERE (content.content_id IN (".implode(",",$new_array).")) AND content.author_id = users.u_id order by FIELD(content.content_id,".implode(",",$new_array).")";
  $result = mysqli_query($con,$query);
if($result!=null && $result->num_rows>0){
    while( $contentrow = $mysqli_fetch_assoc($result){
      print_r($contentrow);
  }
}

$ new_array是我查询数据库的内容ID。打印的$ contentrow将content_id字段设为null,而我在phpmyadmin中获取了正确的id值。

0 个答案:

没有答案