Page 1 of 1

Numeric Directory Search problem

Posted: Thu Oct 21, 2010 6:39 am
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

Re: Numeric Directory Search problem

Posted: Thu Oct 21, 2010 8:13 am
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...

Re: Numeric Directory Search problem

Posted: Thu Oct 21, 2010 2:44 pm
by twinedev

Code: Select all

WHERE com_name REGEXP '^[0-9]'