Using check boxes as part of filter in PHP/SQL
#1
Posted 25 February 2013 - 01:37 AM
#2
Posted 25 February 2013 - 04:47 PM
(This code assumes the type columns in the database table are INT)
$typeList = join(',', array_map('intval', $_POST['Type']));
$sql = "SELECT * FROM APS WHERE Paycode='ANM' AND type IN ($typeList) ORDER BY `Date` DESC";
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns
#3
Posted 25 February 2013 - 05:01 PM
#4
Posted 25 February 2013 - 05:53 PM
eg
$db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE);
$arr = array (
'Jones',
"O'Neill",
'Smith'
);
$list = "'" . join("','", array_map(array($db,'real_escape_string'), $arr)) . "'";
echo $list; //--> 'Jones','O\'Neill','Smith'
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns
#5
Posted 25 February 2013 - 06:23 PM
#6
Posted 25 February 2013 - 10:40 PM
Attached Files
#7
Posted 26 February 2013 - 05:51 AM
Your form method is GET
Your checkboxes are now called SelType
You haven't submitted the query
Apart from that ...
try
$SelType = join(',', array_map('intval', $_GET['SelType']));
$sql = "SELECT * FROM APS WHERE Paycode='ANM' AND Type IN ($SelType) ORDER BY `Date` DESC";
$result = mysql_query($sql);
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns
#8
Posted 26 February 2013 - 06:40 AM
Awesome!! Thanks heaps. It is working and just how I want it to.
#10
Posted 26 February 2013 - 06:26 PM
I added another field into the SQL to use the int value for querying and print the text on the display. I then wrote into the export query my end to assign 1 to commission, 2 to wealthtrac and 3 to rebate to insert into the online SQL. That way I would have the best of both worlds.
#11
Posted 26 February 2013 - 07:30 PM
Better to create a lookup table
TABLE type +------+------------+ | type | typeDesc | +------+------------+ | 1 | commission | | 2 | wealthtrac | | 3 | rebate | +------+------------+
and use a join to get the description
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns
#12
Posted 26 February 2013 - 08:37 PM
That is what I have done internally before I export to SQL, but I guess it makes more sense to reduce the size of the file and server space.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users












