PDA

View Full Version : Sort Alpabetically


bzzrd2
10-03-2006, 07:06 PM
I currently have a number of links in PHP I want to change. My databse has a field "lname". What I want to do is to make these links A thru Z and when clicked, bring back the members whos last name start with the letter clicked. As a newb, I'm kinda lost here. Thanks!

Current Code:
<? if($type<>1) {?>
<a href="showcategory.php?type=1<? echo $strpass1;?>" class="small_link">current</a>
<?
} else echo " current";?>
|
<? if($type<>2) {?>
<a href="gallery.php?type=2<? echo $strpass1;?>" class="small_link">
change</a>
<?
} else echo " gallery";?>
|
<? if($type<>3) {?>
<a href="showcategory.php?type=3<? echo $strpass1;?>" class="small_link">
new today</a>
<?
} else echo " new today";?>
|
<? if($type<>4) {?>
<a href="showcategory.php?type=4<? echo $strpass1;?>" class="small_link">ending
today</a>
<?
} else echo " ending today";?>
|
<? if($type<>5) {?>
<a href="showcategory.php?type=5<? echo $strpass1;?>" class="small_link">expired</a>
<?
} else echo " expired";?>
|
<? if($type<>6) {?>
<a href="showcategory.php?type=6<? echo $strpass1;?>" class="small_link">all</a>
<?
} else echo " all";?>

raf
10-03-2006, 08:31 PM
your links just need to look like
<a href="showlastname.php?lname=a" title="all lastnames starting with a">A</a>

and your select would look like

if (strlen($_GET['lname'] == 1)){
$first_char = $_GET['lname'];
}else{
$first_char = 'a';
}
$sql = "SELECT foobar FROM yourtable WHERE lname LIKE '". $first_char ."%'";

bzzrd2
10-04-2006, 05:24 PM
Thanks Raf
I was hoping to integrate the code with some of the existing sorts.

"All" - "new Today" - etc etc then A B C D ......


It is currently done like so:
|
<? if($type<>3) {?>
<a href="showcategory.php?type=3<? echo $strpass1;?>" class="small_link">
new today</a>
<?

}
if($type==3)
{
$date1=date("Ymd",time())."000000";
$date2=date("Ymd",time())."235959";
$sql.="and date_submitted between $date1 and $date2";

Is the a way to write the if($type==*) statement to retrive alpahabetically from the "lname" column in the members table by letter?

Something like this: (which I know doesn't work)
<? if($type<>5) {?>
<a href="showcategory.php?type=5<? echo $strpass1;?>" class="small_link">
A</a>



if($type==5)
$if (strlen($_GET['lname'] == 1)){
$first_char = $_GET['lname'];
}else{
$first_char = 'a';
}
$sql = "SELECT * FROM ****_members WHERE lname LIKE '". $first_char ."%'";

Thnaks so much for your help!