I have a script that has been running fine for over a year until some "new data" was entered into the database. This data is making the script generate the following warning error:
Warning: Invalid argument supplied for foreach() in /var/www/html/CAMDB/in_mfr_cron.php</b> on line 216
I could go through each new record and try to determine what is causing the problem, but it seems more like searching for a needle through a haystack. What I would rather do is write the error to a file for later viewing, along with the id of the record causing the error.
Since the warning error happens the instance that the foreach() loop is executed, I'm having a hard time seeing how I could get the id for the record that just caused the error. (Although I suspect I will want the ids of the records before and after the error in order to find my culprit.) I can't put anything within the loop because if there is an error, nothing in the loop is executed, and putting anything after it is useless, since it won't get executed until the loop has completed processing all the elements of the array. Here is a snippet of the code I'm using:
//Pull camera information based on current manufacturer
$query = "SELECT camera_id, manufacturer_name, model_name, review_url, plpg_url, currently_manufactured,
zoom_ratio, ccd_sensor_pixels, picture_index_url, device_forum_url, camera_format, pg_uid
FROM camera_general
WHERE manufacturer_name = '$view'
AND mfr_display = 'Yes'
ORDER BY manufacturer_name, model_name;";
$data_result = mysql_query($query) or die(mysql_error());
// Clear arrays from last query.
unset($data_array, $mfr_array);
//Count number of rows returned
$array_cnt = mysql_num_rows($data_result);
//Load data array
for($i=0; $i<$array_cnt; ++$i) {
$data_array[] = mysql_fetch_array($data_result);
}
//Load model_name in seperate array to run natsort
for ($v=0; $v < $array_cnt; ++$v) {
$mfr_array[$v] = $data_array[$v]['model_name'];
}
//Run natsort on model_name array
@natsort($mfr_array);
//Print camera listings by linking to original array by key
foreach($mfr_array as $key => $mfrlist) {
//Reset line_item
$status_selection = 0;
//Check if current camera record is manufactured or discontinued
if ($data_array[$key]['currently_manufactured'] == "Yes") {
$status_selection = 1;
} else {
$status_selection = 2;
}
//Open table row and print model name
$line_item_info[$status_selection] .= "<tr>\n<td width=\"250\" bgcolor=\"".$string_to_find."\">".$data_array[$key]['model_name'];
.
.
.
}
Can someone shed some light on me as to how I can use my code to determine the record that is causing the error? Or am I just going about this all wrong? Any suggestions would help.
Thanks!