查询错误PHP从where子句中选择

时间:2017-03-10 11:48:12

标签: php mysql

我尝试从查询中获取数据表,该数据表从where子句中选择,但不起作用:

<?php
  include "koneksi.php";
    $query=mysql_query("SELECT @rownum := @rownum + 1 AS urutan,t.      id_data, nama_aut, judul_abs, file_abs, status_lolos, status_bayar
  FROM datauser   WHERE status_lolos = "Sudah" t,
  (SELECT @rownum := 0) r");
   $data = array();
   while($r = mysql_fetch_assoc($query)) {
   $data[] = $r;
}

 $i=0;
   foreach ($data as $key) {
    // add new button
   .....
$i++;
 }
   $datax = array('data' => $data);
echo json_encode($datax);
?>

错误

  

解析错误:语法错误,意外'苏达'(T_STRING)

但如果不使用where子句,那就正常工作:

  <?php
  include "koneksi.php";
    $query=mysql_query("SELECT @rownum := @rownum + 1 AS urutan,t.       id_data, nama_aut, judul_abs, file_abs, status_lolos, status_bayar
  FROM datauser   t, 
  (SELECT @rownum := 0) r");
   $data = array();
   while($r = mysql_fetch_assoc($query)) {
   $data[] = $r;
}
 ...

任何人都可以提供帮助,我是新手..

2 个答案:

答案 0 :(得分:0)

不需要为Sudah使用双qoute:

referenced_content

答案 1 :(得分:0)

$ query = mysql_query(&#34; SELECT @rownum:= @rownum + 1 AS urutan,t.id_data,nama_aut,judul_abs,file_abs,status_lolos,status_bayar FROM datauser t WHERE status_lolos =&#39; Sudah&#39 ;,(SELECT @rownum:= 0)r&#34;);