hal_11 Posted November 30, 2011 Share Posted November 30, 2011 Hi all, iv been trying to compile a script that will allow users to select multiple checkboxs that will filter results from db..but to no avail. I have my data stored in mysql and have the queries saved seperatley. i.e. price = 0-500, 500-1000.etc. What im trying to achieve is to allow users to select a checkbox that will execute that particular query and also more importantly allow them to select 'multiple' checkboxes that will filter the results accordingly. I have never attempted to code this before although I am aware that it might involve arrays. If someone could give me a nudge in the right direction that would be great :-) Quote Link to comment Share on other sites More sharing options...
dreamwest Posted November 30, 2011 Share Posted November 30, 2011 Html: <input type='checkbox' name='money[]' value='1' /> <input type='checkbox' name='money[]' value='2' /> <input type='checkbox' name='money[]' value='3' /> Php: $type = $_GET['money']; if($type){ if(is_array($type)){ foreach($type as $x){ echo "$x\n"; } } } You can look at the global by print_r($_GET); Quote Link to comment Share on other sites More sharing options...
hal_11 Posted November 30, 2011 Author Share Posted November 30, 2011 Thanks for the reply, Im not really sure how this will retrieve the information from the database through each query though ..im kind of a newb at this area of coding!...Iv provided a link to what im trying to achieve, that will explain it better than i ever could. http://www.dfs.co.uk/sofas/leather-sofas/ The dfs site filters results on the same pages but also combining each query when a checkbox is selected, i think there is some ajax involved in achieving this also.. Quote Link to comment Share on other sites More sharing options...
dreamwest Posted November 30, 2011 Share Posted November 30, 2011 Yes you just send the value though Http Request <input type='checkbox' onclick='stuff(100);' />, and have a div as the callback, in php just echo the result back. function init() { if (window.XMLHttpRequest){ return new XMLHttpRequest(); }else if(window.ActiveXObject){ return new ActiveXObject("Microsoft.XMLHTTP"); }else{ document.getElementById('err').innerHTML = "Your browser seems to be out of date, Please update!"; return; } }//end init function stuff(amount){ var req = init(); req.open("GET", "url.php?id="+amount, true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200) { document.getElementById('callback_div').innerHTML = req.responseText; } } }; req.send(); }//end related <span id='callback_div'></span> Quote Link to comment Share on other sites More sharing options...
hal_11 Posted November 30, 2011 Author Share Posted November 30, 2011 Thanks, il give that a try..should i create a seperate html file for checkboxes and include the php file or to keep it all as one, as i am currently using one php file and using echo to create the tables? possibly a dumb question but thought id ask Quote Link to comment Share on other sites More sharing options...
dreamwest Posted November 30, 2011 Share Posted November 30, 2011 Up to you, they both post to the same place Quote Link to comment Share on other sites More sharing options...
hal_11 Posted November 30, 2011 Author Share Posted November 30, 2011 yea true..i seem to have some part of it working so far..iv changed the GET url to one of my queries..e.g. price.php..this shows up whenever i click any checkbox option...Do i need to modify onclick='stuff(100); to the matching php file or am i completley missing something lol? And also if more than one is selected will that combine the queries to narrow the results? Thanks once again for all your help! Quote Link to comment Share on other sites More sharing options...
dreamwest Posted November 30, 2011 Share Posted November 30, 2011 change the value inside stuff() to your query Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.