blinks Posted April 16, 2010 Share Posted April 16, 2010 The "for" part of the following code is not working; can anyone help me understand why? $stmt = "SELECT id FROM table"; $result = mysql_query($stmt) or die (mysql_error()); while ($row = mysql_fetch_assoc($result)) { $all_pids[] = $row['id']; } for ($i=0;$i<count($diff);$i++) { if in_array($discrepancy[$i]['id'], $all_pids) { unset($discrepancy[$i]); } else { } i++; } TIA Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted April 16, 2010 Share Posted April 16, 2010 1. is $diff even defined? 2. you are doing $i++ twice, take the second instance of it out. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 16, 2010 Share Posted April 16, 2010 first you should really help others understand what "code not working" means. i can immediately see that it's a mess. several variables are not even set ($discrepancy, $diff), and you're missing an opening ( to your IF statement (and a closing for that matter, too): if (in_array($discrepancy[$i]['id'], $all_pids)) { honestly, if you couldn't see the obvious mistakes, perhaps you should hit the books and read up on basic PHP. I mean that with no disrespect. EDIT: you should be working with the following lines of code at the top of your scripts: ini_set('display_errors', 1); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
blinks Posted April 16, 2010 Author Share Posted April 16, 2010 Thanks! Changing $diff to $discrepancy and removing that 2nd $i++ did the trick :-) Oh, and the brackets around the "if" 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.