Forums
This topic is locked
PHP/MySQL select products with first letter
Posted 27 Jan 2006 20:30:56
1
has voted
27 Jan 2006 20:30:56 Curtis Rostad posted:
I have a db with a table...Field Type Null Default
ID int(11) No
prodnum double Yes NULL
description varchar(255) Yes NULL
quantity varchar(255) Yes NULL
genericdescription varchar(255) Yes NULL
price decimal(10,2) Yes NULL
I have the alphabet a thru z that I want my visitors to be able to select for example the letter G (set to /search_alpha.php?search=g)and it would bring up everything in the description colum that started with the letter G. I have been working on this for 2 days now and I either get all the products of none.
PLEASE HELP!! Here is the code for the search_alpha page
<pre id=code><font face=courier size=2 id=code>
<?php
$colname_Recordset1 = "1";
if (isset($_GET['search'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['search'] : addslashes($_GET['search']);
}
mysql_select_db($database_prescription, $prescription);
$query_Recordset1 = sprintf("SELECT * FROM products WHERE description LIKE '%s' ORDER BY description ASC", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $prescription) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
</font id=code></pre id=code>
Edited by - lavadome on 27 Jan 2006 20:31:23