排序查询ASC的结果[关闭]

I have this code and want to sort the results ASC on the field user.LName

$res=mysqli_query($con,"SELECT user.FName, user.LName, user.HerbalifeID, user.UplineS, registratie.PartnerFName, registratie.PartnerLName, registratie.NaamVIP1, registratie.NaamVIP2, registratie.NaamVIP3 FROM registratie INNER JOIN user ON registratie.userID = user.UserID AND registratie.eventID=".$id);

I have tried placing this at the end of the statement: ORDER BY user.LName ASC"); This did not work. I'm in the learning stage and don't know how to solve this. How can I do this?

ORDER BY user.LName ASC is correct. You're probably just missing a space between it and the id. Check for the sql error

$sql = "
  SELECT user.FName, user.LName, user.HerbalifeID, user.UplineS, registratie.PartnerFName, registratie.PartnerLName, registratie.NaamVIP1, registratie.NaamVIP2, registratie.NaamVIP3 FROM registratie INNER JOIN user ON registratie.userID = user.UserID AND registratie.eventID=$id
  ORDER BY user.LName ASC
";

$res=mysqli_query($con,$sql);

if (!$res) {
    printf("Errormessage: %s
", mysqli_error($conn));
}

First thing before asking here is to use Google. I searched for

Sort results of query ASC

And this is the first result: SQL ORDER BY Keyword

The ORDER BY keyword is used to sort the result-set by one or more columns.

The ORDER BY keyword sorts the records in ascending order by default. To sort the records in a descending order, you can use the DESC keyword.

The query runs after a checkbox is selected. Depending on the $id, the query should search the results and sort ASC.
I tried in several ways to do this with the ORDER BY function but I can't find the solution. I now it will be something stupid, but think it has someting to do with the .$id at the end of the code.
Here is the whole code.

<?php

if(isset($_POST['chk'])=="")
{
?>
  <script>
  alert('Er moet tenminste één checkbox geselecteerd zijn !!!');
  window.location.href='../EVENT/eventIndex.php';
  </script>
<?php
}
$chk = $_POST['chk'];
$chkcount = count($chk);
?>    
<?php  
for($i=0; $i<$chkcount; $i++)
{
$id = $chk[$i];

$res=mysqli_query($con,"SELECT user.FName, user.LName, user.HerbalifeID, user.UplineS, registratie.PartnerFName, registratie.PartnerLName, registratie.NaamVIP1, registratie.NaamVIP2, registratie.NaamVIP3 FROM registratie INNER JOIN user ON registratie.userID = user.UserID AND registratie.eventID=".$id );

while($row=$res->fetch_array())
{
?>