Jump to content

Array question


blinks

Recommended Posts

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

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.