Results 1 to 4 of 4

Thread: mySQL query?!

  1. #1
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default mySQL query?!

    Hey,

    Is it possible to filter out results if the first 2 digits of a txt sting is, for example "o2" ($tariff2)?

    e.g. I have a table with the data:
    o2xnet200min
    o2offpeak
    someotherdata
    moredata
    evenmoredata

    and i only want to show results if the 2st two digits match with $tariff2


    $query="SELECT * FROM handset WHERE 1ST TWO DIGITS OF tariffid='$tariff2";

    Thanks for your help!

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by nikomou View Post
    e.g. I have a table with the data:
    o2xnet200min
    o2offpeak
    someotherdata
    moredata
    evenmoredata
    Are those columns in the table, or actual data in it? If the latter, try something like the following:

    Code:
    $query="SELECT * FROM handset WHERE tariffid LIKE '$tariff2%";
    That will return the result that have any matches like $tariff2 (before the end).

    Example like what you posted above:

    Code:
    $tariff2 = 'o2';
    
    $query="SELECT * FROM handset WHERE tariffid LIKE '$tariff2%";
    That will return the following:

    o2xnet200min
    o2offpeak
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    it is the actuall data, not the columns.

    thanks! i shall give that a go in a min...
    How would i do this using php?

    e.g.
    (if the first 2 digits of $tarifffull = $tariff2) tariff =("O2 Mobile")

    Thanks again

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    That code snippet was in PHP. But that was just a small example.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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
  •