Page 1 of 1

Getting all numbers from DB

Posted: Fri Jan 06, 2006 10:28 am
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!

Posted: Fri Jan 06, 2006 11:35 am
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/+).

Posted: Fri Jan 06, 2006 12:56 pm
by gumphfy
Thanks, I got it :D

simply made it Rlike '^[0-9]'

Posted: Sat Jan 14, 2006 1:18 pm
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!