WHERE子句在PHP中不起作用

时间:2016-09-16 02:06:08

标签: php

我一直在尝试输出已支付部分学生的姓名。 当我不使用'WHERE'子句

时,我可以输出一些东西
$link = mysqli_connect("localhost", "root", "", "test");
$partial = "Partial";
$full = "Full Payment";
$query = "SELECT student_name FROM student WHERE student.status ='".$partial."'";
$query .= "SELECT student_name FROM student ORDER BY student_name";
if (mysqli_multi_query($link, $query)) {
do {
    /* store first result set */
    if ($result = mysqli_store_result($link)) {
        while ($row = mysqli_fetch_row($result)) 
/* print your results */    
{
        printf("%s\n",$row[0]);
        printf("\n");
        printf("<br>");
}
mysqli_free_result($result);
}   
} 
while(mysqli_more_results($link) && mysqli_next_result($link));
}

抱歉问题的格式不好以及我的英语不好。谢谢你,希望你的回复

1 个答案:

答案 0 :(得分:1)

$query = "SELECT student_name FROM student WHERE student.status ='".$partial."'";
$query .= "SELECT student_name FROM student ORDER BY student_name";

此代码将导致$query

SELECT student_name FROM student WHERE student.status ='$partial'SELECT student_name FROM student ORDER BY student_name

当你将两个字符串连接在一起而没有任何分离时。您需要在两个查询之间添加分隔符;。但是,为什么你在这里运行两个查询?