我有一个字符串1集是..
$str = RP-01,RP-11,RP-12,RP-20,RP-75,RP-92
然后我已经改变了sting到这样的数组,准备通过使用implode()
来查询MySQL
$final = (explode(",",$str));
Array ( [0] => RP-01 [1] => RP-11 [2] => RP-12 [3] => RP-20 [4] => RP-75 [5] => RP-92 )
$result = mysql_query("SELECT report.report_id, report_year, report_status, report_type, teacher_name, abstract, report_position, report_name,
GROUP_CONCAT(student_name ORDER BY student_name ASC SEPARATOR ', ') AS student_name
FROM student RIGHT JOIN report ON student.report_id = report.report_id
WHERE report.report_id IN (".implode(',', $final).") ");
最后我尝试使用implode()在MySQL中查询,最后的结果仍然是
mysql_fetch_array() expects parameter 1 to be resource, boolean given in ....
in line : while($row = mysql_fetch_array($result)){ ..}
为什么总是这样。
谢谢所有人。
答案 0 :(得分:1)
添加"
s -
report.report_id IN ('".implode("','", $final)."') ");
必须引用字符串。
答案 1 :(得分:1)
$ result = mysql_query(" SELECT report.report_id,report_year,report_status,report_type,teacher_name,abstract,report_position,report_name, GROUP_CONCAT(student_name ORDER BY student_name ASC SEPARATOR',')AS student_name 来自学生RIGHT JOIN报告on student.report_id = report.report_id WHERE report.report_id IN('" .implode(',',$ final)。")" &#39);