Results 1 to 6 of 6
  1. #1
    Join Date
    May 2008
    Posts
    3

    Unanswered: Get first letter of a result?

    I have a list of members in my database and I would like to make a list but only using the first letter of members name. How can I do that with PostgreSQL/PHP?

    THX

  2. #2
    Join Date
    May 2008
    Posts
    3
    i tried this

    PHP Code:
    <?php
    $result 
    pg_query("SELECT substring(gname, 1, 1) FROM gmembers");
    echo 
    '<select name="gname">';
    while(
    $rad pg_fetch_array($result))                                                                
        {
    echo 
    "<option value=\"$rad[gname]\">$rad[gname]</option>\n";                   
         }
    echo 
    '</select>';
    ?>
    but only got empty field...

  3. #3
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Does this:
    Code:
    SELECT substring(gname, 1, 1) FROM gmembers
    return the desired result?
    If yes, move this to the PHP forum.
    If not, tell us what you expect

  4. #4
    Join Date
    May 2008
    Posts
    3
    Yes, that's what i want!
    How can I move this to PHP forum?

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    thread moved
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    personally Id normally do that sort of thing in the presentation layer, using the PHP function substr, but I could see why youd want to do it in the db, but I'm not familiar with Postgres
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •