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 Quote Link to comment 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. Quote Link to comment 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"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.