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
https://forums.phpfreaks.com/topic/198711-array-question/
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
https://forums.phpfreaks.com/topic/198711-array-question/#findComment-1042828
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.