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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.