How to retrive numbers from database

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
zuby
Forum Newbie
Posts: 3
Joined: Tue Jul 27, 2010 6:18 am
Location: London

How to retrive numbers from database

Post by zuby »

Guys this I presume is simple but I cant get it to work for some reasons.
I want to write a query that will retrieve numbers from my table. I have retailers with first letters as numbers (0-9). My query only retrieves letters and not numbers..any help pls??

Code: Select all

function get_letter($letter){
   $conn = db_connect();
   $query = "select * from retailer where name LIKE '$letter%' GROUP BY name";
   $result = @$conn->query($query);
}
Last edited by Benjamin on Tue Jul 27, 2010 7:43 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
zuby
Forum Newbie
Posts: 3
Joined: Tue Jul 27, 2010 6:18 am
Location: London

Re: How to retrive numbers from database

Post by zuby »

Thank you manzar but my intention is not to count how many rows affected but to fetch all records that their first letters are number ranging from 0-9..e.g 999 inks
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: How to retrive numbers from database

Post by Benjamin »

Code: Select all

select * from retailer where name REGEXP '^[0-9].*' GROUP BY name
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: How to retrive numbers from database

Post by Mordred »

And since you've already made the mistake of posting this in "Security", you might as well read up on mysql_real_escape_string() :)
zuby
Forum Newbie
Posts: 3
Joined: Tue Jul 27, 2010 6:18 am
Location: London

Re: How to retrive numbers from database

Post by zuby »

@benjamin, thanks for the reply but I stil cant get it to work. pls if you have time could u please visit my site then click on (0-9) under browse retailers.
http://connektor.co.uk/vouchers/

Thanks
Post Reply