Matt G Posted September 30, 2011 Share Posted September 30, 2011 Hello everyone, Im fairly new to PHP and MySQL and I have been researching for weeks to find a script that allows me to search specified database tables for checkbox values.. I have come across a number of articles and forums that discuss methods of retrieving/displaying submitted checkbox values &/or populating checkbox forms with database values; but none have explained how to conduct a MySQL table search using selected(checked) checkbox values.. I have a html checkbox form that has values: RED, BLUE, GREEN, SHIRTS, PANTS, SHORTS; my RETAIL DATABASE consists of two tables( each table represents a specific retail store) Store 1(Table_1) and Store 2(table_2); Rows within the table consist of a ID (Primary& Auto_INT); Product_Name(Varchar) and a Product_Description(Text).. For example: I would like the checkbox form to search the "Product_Descriptions" of "table_1" and return the "Product_Name(& description)" from MySQL; but Im having sooo much trouble getting started or finding a usable reference... Here's what I got so far: <form action="...php" method="post" name="search_form" onsubmit="return Checkckeckboxes(this);"> <input type="checkbox" name="search['table_1']" value="blue" id="search1"/> Blue<br/> <input type="checkbox" name="search['table_1']" value="red" id="search2"/> Red<br/> <input type="checkbox" name="search['table_1']" value="green" id="search3"/> Green<br/> <input type="checkbox" name="search['table_1']" value="shirts" id="search4"/> Shirts<br/> <input type="checkbox" name="search['table_1']" value="pants" id="search5"/> Pants<br/> <input type="checkbox" name="search['table_1']" value="shorts" id="search6"/> Shorts<br/> <input type="submit" value="search"/> </form> //not sure what to write in the "id" field(or if its needed) Database name is: RETAIL_STORES Table_1 ( represents store number one) Id (primary, auto int) //i.e. 1 Product_Name (Varchar) //i.e. Golf Shorts Product_description (Text) //i.e. Green, Shorts, etc Table_2 (represents store number two) Id (primary, auto int) //i.e. 1 Product_Name (Varchar) //i.e. basketball shirt Product_description (Text) //i.e. red, shirt I want this form to search for selected(checked) values in Table_1 via product_Description and display the Product_Name and description to the user.. But im sure my form parameters have NOT accomplished this and I need code help to achieve my goal.. I know someone on this forum can help or at least get me started in the right direction..PLEASE HELP!!!!!! Link to comment https://forums.phpfreaks.com/topic/248166-searching-database-tables-with-checkbox-forms/ Share on other sites More sharing options...
gristoi Posted September 30, 2011 Share Posted September 30, 2011 Hope this points you in the right direction: <?php $query = "SELECT `ID`,`Product_Name`, `Product_Descriptions` FROM table_1 "; $result = mysql_query($query); $form = '<form action="...php" method="post" name="search_form" onsubmit="return Checkckeckboxes(this);">'; while($row = mysql_fetch_assoc($result)){ $form .='<input type="checkbox" name="'.$row['Product_Name'].'" value="'.$row['Product_Description'].'" id="'.$row['ID'].'"/> "'.$row['Product_Description'].'"<br/>'; } $form.='<input type="submit" value="search"/>'; $form.='</form>'; echo $form; Link to comment https://forums.phpfreaks.com/topic/248166-searching-database-tables-with-checkbox-forms/#findComment-1274374 Share on other sites More sharing options...
Matt G Posted October 1, 2011 Author Share Posted October 1, 2011 Thank you for the help Gristoi, I'm currently working through a few issues with my actual form code...but this is def a step in the right direction and I greatly appreciate the help ! Thnx again!! Link to comment https://forums.phpfreaks.com/topic/248166-searching-database-tables-with-checkbox-forms/#findComment-1274740 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.