greens85 Posted October 29, 2010 Share Posted October 29, 2010 Hi all, I have a situation where I need to remember what check boxes where checked over pagination, I have managed to do this via the use of this: http://jamesfunk.com/wordpress/?p=65 The problem is that as the code stood: <input type="checkbox" name="compare" value="<?php echo $list['jobseeker_id'];?>" class="remember_cb"/> It was treating one ticked checkbox as them all because they all have the same name and are in the a while loop! I countered this by changing the code to: <input type="checkbox" name="compare<?php echo $list['jobseeker_id']?>" value="<?php echo $list['jobseeker_id'];?>" class="remember_cb"/> Which effectively now makes the checkbox name unique... i.e. compare{id}. The problem with this is that I can now no longer process it. This is my processing code: $jobseekers = $_POST['compare']; $i = 0; for($i; $i<count($jobseekers); $i++){ $query = "SELECT * FROM jobseekers WHERE jobseeker_id = '$jobseekers[$i]'"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { // Spit out the required data } } As you can see I am trying to get the data from $_POST['compare'], which will obviously now be blank as I have had to make the name unique.... the trouble is I'm not sure how to actually process this. Can anyone help me out here? any help or advice would be greatly appreciated! many thanks, Greens85 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 29, 2010 Share Posted October 29, 2010 If you change the checkboxes to <input type="checkbox" name="compare[<?php echo $list['jobseeker_id']?>]" value="<?php echo $list['jobseeker_id'];?>" class="remember_cb"/> They should process again by changing the first line in your next code block to if( is_array($_POST[compare']) ) { $jobseekers = $_POST['compare'][]; } Let me know how this works. Quote Link to comment Share on other sites More sharing options...
greens85 Posted October 29, 2010 Author Share Posted October 29, 2010 Hi Pikachu2000, You code returned the following fatal error: Fatal error: Cannot use [] for reading in /path/removed on line 34 if(is_array($_POST['compare'])) { $jobseekers = $_POST['compare'][]; // line 34 } I noticed some typos, such as if( is_array($_POST[compare']) ) { $jobseekers = $_POST['compare'][]; } On the first post you had one ' but not the one preceding it, so I made that assumption that it should be added, not sure if this is what has broke the code but in my limited experience I doubt it. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 29, 2010 Share Posted October 29, 2010 The extra empty brackets are a typo, and shouldn't be there . . . should be if(is_array($_POST['compare'])) { $jobseekers = $_POST['compare']; // line 34 } And yes, you're correct to add the other single quote in the array index. Quote Link to comment Share on other sites More sharing options...
greens85 Posted October 29, 2010 Author Share Posted October 29, 2010 No errors occurring now, but no results either... Would it be easier for me to attach the processing script, as it may be something else in the script? Also if you want to test it: http://www.beta.teachingagencies.co.uk/search_jobseekers.php Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 29, 2010 Share Posted October 29, 2010 Yeah, it would be helpful to see the rest of the code. Quote Link to comment Share on other sites More sharing options...
greens85 Posted October 29, 2010 Author Share Posted October 29, 2010 No problem, Here is my processing script (that should display the 'compared' candidates)! If you need the preceding script, let me know. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
greens85 Posted November 1, 2010 Author Share Posted November 1, 2010 Still stuck with this one, anyone got any thoughts on it? 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.