Forum Moderators: coopster

Message Too Old, No Replies

Filtering MySQL recordset using checkbox array values

Using PHP, MySQL, Dreamweaver

         

FatLarry

7:59 pm on May 4, 2009 (gmt 0)

10+ Year Member



Please forgive any 'obvious' errors in my post - I'm a major novice with PHP, MySQL...

I have scoured the internet forums looking for a simple solution to what (i think) is a simple requirement:

I want to filter a recordset based on the ID values passed by multiple checkbox array values.

More specifically, I am using Dreamweaver and have created a 'request quote' form which lists a number of products, each with an associated checkbox to select the product if required...the form successfully passes the checkbox values on (in the form of an array which passes multiple productID values) to a form on a separate php page where further user input is required using text boxes (customer name, tel no, quantity required, etc).

My problem is that I can't work out how to create a filter for a recordset that only contains the selected productID values passed by the form checkbox array!

Any help much appreciated.

brotherhood of LAN

8:14 pm on May 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to the forums fatlarry,

You will want your query to look something like

SELECT * FROM table WHERE productID IN (1,2,7)

"IN" is the alternative used for multiple values rather than having something like

SELECT * FROM table WHERE productID = 1 OR productID = 2 OR productID = 7

FatLarry

3:29 pm on May 9, 2009 (gmt 0)

10+ Year Member



Hi & Thanks for the welcome.

I am still struggling with this one, maybe some specific code details may illustrate the problem..

I have a form incorporating a checkbox to select the required products from a dynamic list..

<input name="selectedProduct[]" type="checkbox" id="selectedProduct[]" title="select products" value="<?php echo $row_productList['productID']; ?>" />

This appears to work fine and, on SUBMIT button click, the form POSTS multiple selcted product IDs to a second form page where I need to filter the Product IDs in a recordset called 'checkBoxFilter'.

This is where it all goes pear shaped...

As a PHP / MySQL novice, I am relying on Dreamweaver to form the relevant code for my filters using the advanced tab of the recordest propertires.

I need to filter the 'checBoxFilter' recordest so that only the productIDs that were selected on the previous form are shown. In the Dreamweaver recordest edit window I guess I need something like...

SELECT productID
FROM tbproducts
WHERE productID = selProdID IN ("ANY PRODUCT ID VALUE HERE?")

selProdID is defined as $_GET['$selectedProduct']

Obviously, I need a suitable expression for the"ANY PRODUCT ID VALUE HERE?" that calls up all productID values passed on by the array.

Any help / ideas much appreciated - as you can tell I am very new to this coding, and I'm pulling my hair out over this.

Thanks