Home > Archive > PHP SQL > August 2004 > "Order By" Help
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
"Order By" Help
|
|
| trey_anastasio 2004-05-23, 6:30 pm |
| I am a newbie at SQL code and was wondering if someone could help me
accomplish the following:
On my site, I have an alumni database for a school. It's at
http://www.stcharlesprep.org/alumnidev/alumnisearch.php I'd like
to find out how to write the SQL code to order the names properly.
First, if keyword parameter or 'Last Name' is given, I'd
like it to order by YEAR. If YEAR is the variable, I'd like it
to order by LAST NAME.
Here is the code - can someone please take a look see and assist?
Thanks.
On page alumnisearch.php -
<?php require_once('../Connections/connAlumni.php');
mysql_select_db(database_connAlumni, connAlumni);
query_rsAlumni = "SELECT `Year`, LName, FName, Email FROM
tb_alumni";
rsAlumni = mysql_query(query_rsAlumni, connAlumni)
or die(mysql_error());
row_rsAlumni = mysql_fetch_assoc(rsAlumni);
totalRows_rsAlumni = mysql_num_rows(rsAlumni);
?>
----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums
| |
| tox_yray 2004-08-18, 3:56 pm |
| you could try a switch here... like (in pseudocode here)
switch()
case "year"
query_rsAlumni = "SELECT `Year`, LName, FName, Email FROM
tb_alumni ORDER BY".lastname;
case "lastname"
query_rsAlumni = "SELECT `Year`, LName, FName, Email FROM
tb_alumni ORDER BY".year;
case "firstname"
case "year"
query_rsAlumni = "SELECT `Year`, LName, FName, Email FROM
tb_alumni ORDER BY".whatever_you_want_to_order_it_by;
else
'whatever you want to put as an else case.'
----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums
|
|
|
|
|