Jump to content

[SOLVED] Simple A-Z + "#" link list not working?


corychauvin

Recommended Posts

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

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.