corychauvin Posted March 1, 2007 Share Posted March 1, 2007 Hello, i need to build a simple A-Z list where clicking on each letter will extract the rows from a database that start with the selected letter. I have it working only i need to include a "#" sign so that and records that start with a number are selected. Right now when i click the "#" sign it pulls all the records from the database not just the ones that start with a number. So on the letter links each letter has a link like this <a href="searchByList.php?index=#" target="mainFrame">#</a> <a href="searchByList.php?index=A" target="mainFrame">A</a> <a href="searchByList.php?index=B" target="mainFrame">B</a> <a href="searchByList.php?index=C" target="mainFrame">C</a> <a href="searchByList.php?index=D" target="mainFrame">D</a> etc etc... and the recieving page has this... $colname = "index"; if (isset($_GET['index'])) { $colname = (get_magic_quotes_gpc()) ? $_GET['index'] : addslashes($_GET['index']); } if ($colname == "#"){ $colname = preg_replace("/[^0-9]/", "" , $colname); } mysql_select_db($database_SunParlour, $SunParlour); $query_rsSearchList = "SELECT * FROM products,supplier WHERE productName LIKE '$colname%' AND products.supplier_id = supplier.supplier_id ORDER BY productName ASC "; I've tried different reg exp but nothing seems to pull only the records that start with a number??? Like i said all the letters work fine, if i click on a i get only records that start with "a"... etc, but clicking the "#" link returns all rows in the database Link to comment https://forums.phpfreaks.com/topic/40718-solved-simple-a-z-link-list-not-working/ Share on other sites More sharing options...
effigy Posted March 1, 2007 Share Posted March 1, 2007 Passing # through that replace yields nothing--an empty string. To match any number, you'll need to use MySQL's REGEXP operator. Link to comment https://forums.phpfreaks.com/topic/40718-solved-simple-a-z-link-list-not-working/#findComment-197098 Share on other sites More sharing options...
corychauvin Posted March 1, 2007 Author Share Posted March 1, 2007 Thanks, changing "#" to "0" plus changing my code worked. $colname = "index"; if (isset($_GET['index'])) { $colname = (get_magic_quotes_gpc()) ? $_GET['index'] : addslashes($_GET['index']); } if ($colname == "0"){ $clause = " productName REGEXP '^[0-9]+' "; }else{ $clause = " productName LIKE '$colname%' "; } mysql_select_db($database_SunParlour, $SunParlour); $query_rsSearchList = "SELECT * FROM products,supplier WHERE $clause AND products.supplier_id = supplier.supplier_id ORDER BY productName ASC"; Link to comment https://forums.phpfreaks.com/topic/40718-solved-simple-a-z-link-list-not-working/#findComment-197162 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.