Jopeth Deza Jopeth Deza - 2 months ago 7
PHP Question

WHERE clause doesn't work in PHP

I've been trying to output the name of the students who have paid in partial.
I can output something when I doesn't use the 'WHERE' clause

$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));
}


Sorry for the bad format of the question and for my bad english. Thank you and hoping for your responses

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

This code will result in $query being:

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

As you are concatenating the two strings together without any separation. You would need to add a separator ; between the two queries. However, why are you running two queries here?