homepage Welcome to WebmasterWorld Guest from 50.17.21.7
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Simple A-Z link list for searching mysql database
corychauvin




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

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




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

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




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved