Web Analytics Made Easy -
StatCounter Sort Alpabetically - CodingForum

Announcement

Collapse
No announcement yet.

Sort Alpabetically

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sort Alpabetically

    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:
    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";?>

  • #2
    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
    PHP Code:
    if (strlen($_GET['lname'] == 1)){
      
    $first_char $_GET['lname'];
    }else{
      
    $first_char 'a';
    }
    $sql "SELECT foobar FROM yourtable WHERE lname LIKE '"$first_char ."%'"
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment


    • #3
      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:
      PHP Code:

                  <? if($type<>3) {?>
                  <a href="showcategory.php?type=3<? echo $strpass1;?>" class="small_link"> 
                  new today</a> 
                  <?
      PHP Code:
      }
      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)
      PHP Code:
      <? if($type<>5) {?>
                  <a href="showcategory.php?type=5<? echo $strpass1;?>" class="small_link"> 
                  A</a>
      PHP Code:
      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!

      Comment

      Working...
      X