Benny Benny - 6 months ago 9
PHP Question

Sort results of query 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?

Answer

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\n", mysqli_error($conn));
}