mysql_query返回value和null,但应该只有值

时间:2014-05-22 06:12:26

标签: php mysql

我通过从php返回json表示法中的mysql_query获得了一些空值。有些字段,如bookid,名称,作者,持续时间都是返回值,有些则不是!但是我在DBVisualizer中输入相同的查询,我只有价值...这里的问题是什么?

    echo $myuserid . "idcheck";
    $q1 = "select u.address as address, u.postcode as postcode, u.town as town, u.telnumber, u.mail, b.bookid as bookid, b.name as name, b.author as author, s.duration as duration from status s, book b, user u where s.bookid = b.bookid and s.borroweruserid = u.userid and s.borroweruserid = $myuserid";
    echo $q1;
    $sth = mysql_query($q1) or die(mysql_error());

        while($rowla = mysql_fetch_assoc($sth)) {

     $rows[] = array(
      'address' => $rowla['address'],
      'postcode' => $rowla['postcode'],
      'town' => $rowla['town'],
      'telnumber' => $rowla['telnumber'],
      'mail' => $rowla['mail'],
      'bookid' => $rowla['bookid'],
      'name' => $rowla['name'],
      'author' => $rowla['author'],
      'duration' => $rowla['duration']);
     // 'pic' => base64_encode($row['pic']  
    //$rows[] = $r;
       }
       $j1 = json_encode($rows);

UPDATE:将error_reporing放到php脚本时没有任何工作(没有执行查询)并且通过添加print_r($ rowla)之后 仍然得到这个反馈(第二个查询正在做同样的 - 只是有点不同): http://s24.postimg.org/4wpu29zwl/Screen_Shot_2014_05_22_at_08_45_02.png

1 个答案:

答案 0 :(得分:0)

你错过了你的sql。我想。

$q1 = "SELECT u.address AS address, u.postcode AS postcode, u.town AS town, u.telnumber, u.mail, b.bookid AS bookid, b.name AS name, b.author AS author, s.duration AS duration from status s, book b, user u WHERE s.bookid = b.bookid AND s.borroweruserid = u.userid AND s.borroweruserid = '".$myuserid."'";