i have a list of names in a mysql table. How can i sort them alphabetically as they are pulled and i put them on a website with PHP?
Printable View
i have a list of names in a mysql table. How can i sort them alphabetically as they are pulled and i put them on a website with PHP?
append ORDER BY clause to the end of the sql statement to sort, e.g. "SELECT * FROM table ORDER BY LastName ASC" (or DESC)
thanks again chris. I didn't know that you knew this much PHP. Is this all from messing with vB?
I learnt SQL in my Access days, whilst it differs it's mostly the same. PHP i've only been doing for a few months but it was pretty easy for me to pick up as I knew it's close mate Perl quite well already.
Here's the second part of your Q BTW which I missed first time
that's a pretty generic example but it's easy to build up :)PHP Code:<?php
// connect to database
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("table", $db);
// construct SQL
$sql = "SELECT * FROM table WHERE something=somethingelse ORDER BY AField DESC";
// perform query
$result = mysql_query($sql);
// output to page
while ($row = mysql_fetch_array($result)) {
printf("%s ", $row["AField"]);
print '<br>';
}
?>
thanks again, it works great :)
lol, nothing to do with PHP; SQL mate ;)Quote:
Originally posted by sail3005
thanks again chris. I didn't know that you knew this much PHP. Is this all from messing with vB?
well, the query bit anyway :)