How to make table be in alphabetical order?

Hey guys, need some help with this table, the table works fine but when i try to use the ORDER BY function to have it in alphabetical order i get the following error. Any help in getting this table in alphabetical order would be very helpful!

Notice : Trying to get property ‘num_rows’ of non-object.

<?php

$conn = mysqli_connect(‘localhost’,‘root’,’’, ‘working’);
if ($conn-> connect_error) {
die(“Connection failed:” .$conn-> connect_error);
}$sql = “SELECT Microphone_Audio_Kits, Microphone_Equip_Condition, Camera_Kits, Camera_Equip_Condition, Lighting_Kits, Lighting_Equp_Condition, Monitors_TriPods_Extras, Monitors_TriPods_Extras_Condition FROM equipment ORDER BY ASC”;
$result = $conn-> query($sql);
$sql = “SELECT Microphone_Audio_Kits, Microphone_Equip_Condition, Camera_Kits, Camera_Equip_Condition, Lighting_Kits, Lighting_Equp_Condition, Monitors_TriPods_Extras, Monitors_TriPods_Extras_Condition FROM equipment ORDER BY “;
$result = $conn-> query($sql);
if ($result-> num_rows > 0) {
while ($row = $result-> fetch_assoc()) {
echo “

”.$row[‘Microphone_Audio_Kits’].” ”.$row[‘Microphone_Equip_Condition’]." ".$row[‘Camera_Kits’]." ".$row[‘Camera_Equip_Condition’]." ".$row[‘Lighting_Kits’]." ".$row[‘Lighting_Equp_Condition’]." ".$row[‘Monitors_TriPods_Extras’]." ".$row[‘Monitors_TriPods_Extras_Condition’]." ";
}
echo “”;
}
else {
echo “0 result”;
}
?>

Well, this is an invalid command. You did not tell the query what you are ordering by.
If you want it to display in a set order, you need to tell it which field you want it sorted on.
Also, your code makes little sense. You run two queries one after another. Why? The first $result gets overwritten by the second one. Also, you don’t need to tell ALL of the field names, just select them all. Something like: SELECT * FROM equipment ORDER BY equipment_name
But, of course it depends on your table layout which you did not show us. Normally, for an equipment list, you would have the name of the equipment, the type of equipment, condition, etc. Then, pull them all out and display them alphabetically.
I am assuming this is for a class project… You might want to read up on how to create a database layout first. You seem to list everything as a separate field and that is not really the way to do this type of project. Hope this makes sense to you.

Sponsor our Newsletter | Privacy Policy | Terms of Service