PDA

View Full Version : mySQL query?!



nikomou
03-10-2007, 09:56 PM
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!

thetestingsite
03-11-2007, 05:03 AM
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:




$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:



$tariff2 = 'o2';

$query="SELECT * FROM handset WHERE tariffid LIKE '$tariff2%";


That will return the following:



o2xnet200min
o2offpeak


Hope this helps.

nikomou
03-11-2007, 01:32 PM
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

thetestingsite
03-11-2007, 04:47 PM
That code snippet was in PHP. But that was just a small example.