Numeric Directory Search problem

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
adsegzy
Forum Contributor
Posts: 184
Joined: Tue Jul 28, 2009 9:26 am

Numeric Directory Search problem

Post by adsegzy »

Hello friends,

I am designing directory pages where companies' names can be searched alphabetically. I created pages for each alphabet and created some link has A | B | C | D | E ..........................X | Y | Z | 0-9

When the visitor click on any alphabet, he will be taken to the page where companies' names that start with that alphabet are listed. 0-9 will lead to the page where companies' name that start with numbers are listed. I use the code below to get the results from my database.

Code: Select all

$sql = mysql_query("SELECT * FROM $com_name WHERE com_name LIKE 'A%'");
for A Page

Code: Select all

$sql = mysql_query("SELECT * FROM $com_name WHERE com_name LIKE 'B%'");
for B Page

Code: Select all

$sql = mysql_query("SELECT * FROM $com_name WHERE com_name LIKE 'C%'");
for C Page etc

but when i tried the below for numeric page, it didn't work

Code: Select all

$sql = mysql_query("SELECT * FROM $com_name WHERE com_name LIKE '0%, 1%, 2%, 3%, 4%, 5%, 6%, 7%, 8%, 9%'");
i also tried

Code: Select all

$sql = mysql_query("SELECT * FROM $com_name WHERE com_name LIKE '0-9%'");
and

Code: Select all

$sql = mysql_query("SELECT * FROM $com_name WHERE com_name LIKE '0%' OR '1%' OR '2%' OR '3%' OR '4%' OR '5%' OR '6%' OR '7%' OR '8%' OR '9%'");
what can i do? pls help me
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Numeric Directory Search problem

Post by requinix »

1. You're doing it wrong. Doesn't having 27 nearly-identical pages strike you as a bit unusual?
2.

Code: Select all

field LIKE string OR field LIKE string OR field LIKE string...
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Numeric Directory Search problem

Post by twinedev »

Code: Select all

WHERE com_name REGEXP '^[0-9]'
Post Reply