Getting all numbers from DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gumphfy
Forum Newbie
Posts: 23
Joined: Fri Jan 06, 2006 10:18 am

Getting all numbers from DB

Post by gumphfy »

Hi, I have a slight problem, one I can't really figure out. I have tried to search for the solution, but I just didn't know what to search for. I'm pretty much a PHP n00b, but I'm learning :p

Anyway, what I'm am doing is getting all names from a DB beginning with a certain letter like:

Code: Select all

$result = mysql_query("SELECT * FROM test WHERE name LIKE 'a%'");

while($row = mysql_fetch_array($result))

{
echo $row[name'];
}
I want to do the same thing with numbers.. I know I can just put 1% in, but I want to get all names beginning with a number, regardless of what the number is, (0-9).

There's probably a simple solution to this, but what that might be, I hope you can tell me, or at least give me some guidelines on how to figure it out.

Thanks in advance!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You could write it as "LIKE '1%' OR LIKE '2%' ..." but if you are using mysql the use of a regular expression seems more appropriate (^\d/+).
gumphfy
Forum Newbie
Posts: 23
Joined: Fri Jan 06, 2006 10:18 am

Post by gumphfy »

Thanks, I got it :D

simply made it Rlike '^[0-9]'
gumphfy
Forum Newbie
Posts: 23
Joined: Fri Jan 06, 2006 10:18 am

Post by gumphfy »

Hi me again...sorry to bump this thread, but I thought it was better than starting a new thread, since it almost about the same thing.

OK. How would I go about doing the same thing, as above, with japanese characters?
...well actually it isn't japanese characters, but rather something like this: (sorry, I'm not familiar with the correct terminology)

Code: Select all

ス
(sorry about the php tag, it was the only way I was able to display it...)

So basically I have to fetch every name beginning with a &...correct?

I've been going at it, all day long, trying to look through both google and the ever-so-endless mysql manual, but, again, I do not know excatly what to search for.
So if anyone could give me a little puch in the right direction, it would be much appreciated.

Thanks in advance!
Post Reply