I’m trying to sort the output of SQL out in ascending order. but it doesn’t work. My code is like below
if($result->num_rows>0){
while($row = $result->fetch_assoc()){
print "<tr><td>"
. $row["id"] . "</td><td>"
. $row["firstname"] . "</td><td>"
. $row["lastname"] . "</td><td>"
. $row["mphone"] . "</td><td>"
. $row["hphone"] . "</td><td>"
. $row["email"] . "</td><td>"
. $row["address"] . "</td><td>"
. $row["city"] . "</td><td>"
. $row["zip"] . "</td><td>"
. $row["state"] . "</td><td>"
. $row["country"] . "</td><td>"
. $row["age"] . "</td><td>"
. $row["height"] . "</td><td>"
. $row["transport"] . "</td><td>"
. $row["day"] . "</td><td>"
. $row["gender"] . "</td><td>"
. $row["message"] . "</td><tr>";
}
}
SELECT * FROM mytable
ORDER BY Country DESC;
Rubble
October 18, 2015, 9:40pm
3
What happens if you change DESC to ASC?
Are you certain
Country === country ???
* I can only guess, “doesn’t work” by itself says essentially nothing to me.
Error messages and / or more detail about unexpected results would be more helpful
1 Like
Tripple
October 18, 2015, 10:13pm
6
The data doesn’t show whenever I add the block below
SELECT * FROM mytable
ORDER BY Country DESC;
What do you see with the else bit added on
if($result->num_rows>0){
while($row = $result->fetch_assoc()){
print "<tr><td>"
. $row["id"] . "</td><td>"
. $row["firstname"] . "</td><td>"
. $row["lastname"] . "</td><td>"
. $row["mphone"] . "</td><td>"
. $row["hphone"] . "</td><td>"
. $row["email"] . "</td><td>"
. $row["address"] . "</td><td>"
. $row["city"] . "</td><td>"
. $row["zip"] . "</td><td>"
. $row["state"] . "</td><td>"
. $row["country"] . "</td><td>"
. $row["age"] . "</td><td>"
. $row["height"] . "</td><td>"
. $row["transport"] . "</td><td>"
. $row["day"] . "</td><td>"
. $row["gender"] . "</td><td>"
. $row["message"] . "</td><tr>";
}
} else {
echo '$result->num_rows is ' . $result->num_rows;
}
Tripple
October 18, 2015, 11:33pm
8
Thank you so much. I’ll try it and get back to you
Nothing. no difference. Just shows the results
Tripple:
Just shows the results
That sounds like the script is working.
If not, please explain.
Tripple
October 19, 2015, 11:30am
11
@Mittineague Yes the script is working. I want it to be sorted by country, or any other field o fmy choice
Can you post your actual code? There must be something else in there which is causing you an issue…
Might it be they are sorting but not as you expect them to?
Does it look anything like this collation effect example?
https://dev.mysql.com/doc/refman/5.0/en/charset-collation-effect.html
Drummin
October 20, 2015, 1:59am
14
I like this answer however I am not sure OP understood the meaning and corrected the issue.
system
Closed
January 19, 2016, 9:00am
15
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.