Welcome to WebmasterWorld Guest from 54.226.147.190

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Simple A-Z link list for searching mysql database

     

corychauvin

7:04 pm on Feb 28, 2007 (gmt 0)

5+ Year Member



Hello,

I'm trying to set-up a simple A-Z list so that people can search a mysql database by each letter. Click on "A" get all records in the DB that start with "A". I have it working no problem but i want to be able to add "#" so that the user can get all records that start with a Number.

For some reason the query i'm running won't grab any records that start with a number?

here is the query:

SELECT *
FROM products,supplier
WHERE productName LIKE 'colname%' AND products.supplier_id = supplier.supplier_id
ORDER BY productName ASC

And the query string for the "#" is:

searchByList.php?index=1

for each of the Letters i have
searchByList.php?index=A
searchByList.php?index=B
etc etc....

it works on the letters but not on the number?

I'm using Dreamweaver so the 'colname%' has default value of -1 and a runtime value of $_GET['index']

any ideas on changing the query to grab the records with numbers would be helpful?

Thanks.

eelixduppy

8:21 pm on Feb 28, 2007 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Welcome to WebmasterWorld, corychauvin!

Try something like the following and tell me what you get:


$query = "SELECT * FROM products,supplier WHERE productName LIKE '".[url=http://us2.php.net/mysql-real-escape-string]mysql_real_escape_string[/url]($_GET['index'])."%' AND products.supplier_id = supplier.supplier_id ORDER BY productName ASC";

parorrey

12:48 pm on Mar 2, 2007 (gmt 0)

10+ Year Member



i think you should use regexp rather than LIKE.

SELECT *
FROM products,supplier
WHERE productName REGEXP '^[0-9]+' AND products.supplier_id = supplier.supplier_id
ORDER BY productName ASC

-Ali

 

Featured Threads

Hot Threads This Week

Hot Threads This Month