SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast Ninth Dimension's Avatar
    Join Date
    Sep 2002
    Location
    London, England.
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    pulling data from a MySQL database based on the first letter of the field

    Sorry for the long subject title, but sums up my question nicely

    What mySQL query should I use to pull data from a database based on the first letter of the field.

    it's for a very simple address book script i'm writing where they can list names based onm there surnames first letter.

    I used to be able to do this, but as i've been away from PHP and MySQL programming for a while i've forgotten the best script query to use.

  2. #2
    SitePoint Enthusiast Ninth Dimension's Avatar
    Join Date
    Sep 2002
    Location
    London, England.
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In addition, i'd like to preform a simple check at the top of the page to see that only a standard leter is being added to the query ( i.e. a-z)

    I could do:
    PHP Code:
    if (($var == 'a') OR ($var == 'b') OR ($var == 'c').......($var == 'z')) 
    but that would be silly

  3. #3
    Idea Developer
    Join Date
    Sep 2000
    Location
    Bethlehem, PA
    Posts
    521
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ninth Dimension
    In addition, i'd like to preform a simple check at the top of the page to see that only a standard leter is being added to the query ( i.e. a-z)

    I could do:
    PHP Code:
    if (($var == 'a') OR ($var == 'b') OR ($var == 'c').......($var == 'z')) 
    but that would be silly

    eregi ('[a-z]',$var)
    Professional PHP programing / Hosting
    aim: downtoi3iz icq: 74637813

  4. #4
    SitePoint Enthusiast Ninth Dimension's Avatar
    Join Date
    Sep 2002
    Location
    London, England.
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by necrominator
    eregi ('[a-z]',$var)
    thanx for the info, but how would i use this within an if statement??

    UPDATE: don't worry, i've figured it out now
    Last edited by Ninth Dimension; May 22, 2003 at 10:34.


Bookmarks

Posting Permissions

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