jrm Posted August 18, 2008 Share Posted August 18, 2008 I am having trouble finding my error and all I get is undefined offset. Can I get some help? $ConfCtr = 0; $ConfQuery = "Select DTG_Start, DTG_End, ConfTypeID, AB From PNC_be.Confid Where PNCID = " . $PNCID . ";"; $ConfResults = mysql_query($ConfQuery, $link) or die("\n<p> Could not run ConfQuery : " . $ConfQuery . " : " . mysql_error()); if(mysql_num_rows($ConfResults)==0) { //$ConfCtr++; $Conf = array($ConfCtr => array("Type" => "Unknown", "DTG_Start" => "Unknown","DTG_End" => "Unknown", "Approved" => "Unknown","Total" => "Unknown" )); } else { while($ConfRow = mysql_fetch_array($ConfResults, MYSQL_ASSOC)) { $TypeQuery = "SELECT TypeID,ConfType From PNC_be.TypeConf Where TypeID = " . $ConfRow["ConfTypeID"] .";"; $TypeResults = mysql_query($TypeQuery, $link) or die("\n<p> Could not run TypeQuery : " . $TypeQuery . " : " . mysql_error()); if(mysql_num_rows($TypeResults)==0) { $Type = "Unknown"; } else { $TypeRow = mysql_fetch_array($TypeResults, MYSQL_ASSOC); $Type = $TypeRow["ConfType"]; } $Start = strtotime($ConfRow["DTG_Start"]); $End = strtotime($ConfRow["DTG_End"]); $temp = $End - $Start; $tempmin = $temp / 60; $hours = floor($temp / 60 / 60); $minutes = fmod($tempmin, 60); $ApprovedBy = ($ConfRow["AB"]==0) ? "Unknown" : StaffName($ConfRow["AB"]) ; $Conf = array($ConfCtr => array("Type" => $Type, "DTG_Start" => strtotime($ConfRow["DTG_Start"]), "DTG_End" => strtotime($ConfRow["DTG_End"]), "Approved" => $ApprovedBy, "Total" => $hours . "hrs, " . $minutes . "mins")); $ConfCtr++; } // more code here of similiar functions but different tables echo $ConfCtr; // for debugging only if(strcmp($Conf[0]["Type"],"Unknown")<>0) // [b]line 190[/b] { ?> <table width = 100% border = 1> <tr> <td width = 15% align = right>Confinements</td> <td width = 85%> <table width = 100% border = 1> <tr> <td width = 100% align = center> No Records or Unknown </td> </tr> </table> </td> </tr> </table> <? } else { ?> <table width = 100% border = 1> <tr> <td width = 15% align = right>Confinements</td> <td width = 85%> <table width = 100% border = 1> <tr> <td width = 20%>Type</td> <td width = 20%>Start</td> <td width = 20%>End</td> <td width = 20%>Total Time</td> <td width = 20%>Approved by</td> </tr> <? for($i = 0; $i <= $ConfCtr - 1; $i++) { ?> <tr> <td width = 20%><? echo $Conf[$i]["Type"]; ?></td> <td width = 20%><? echo date("d M Y Hi", $Conf[$i]["DTG_Start"]); ?></td> <td width = 20%><? echo date("d M Y Hi", $Conf[$i]["DTG_End"]); ?></td> <td width = 20%><? echo $Conf[$i]["Total"]; ?></td> <td width = 20%><? echo $Conf[$i]["Approved"]; ?></td> </tr> <? } ?> </table> </td> </tr> </table> <? } ?> Output 11<br /> <b>Notice</b>: Undefined offset: 0 in <b>/var/www/html/PNCDetails.php</b> on line <b>190</b><br /> <table width = 100% border = 1> <tr> <td width = 15% align = right>Confinements</td> <td width = 85%> <table width = 100% border = 1> <tr> <td width = 100% align = center> No Records or Unknown </td> </tr> </table> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/120239-solved-undefined-offset-0/ Share on other sites More sharing options...
uniflare Posted August 18, 2008 Share Posted August 18, 2008 is this the only error? (actually its a notice but hey). Can u show us line 190? i'm guessing its to do with your $ConfRow some how. Link to comment https://forums.phpfreaks.com/topic/120239-solved-undefined-offset-0/#findComment-619400 Share on other sites More sharing options...
jrm Posted August 18, 2008 Author Share Posted August 18, 2008 line 190: if($Conf[0]["Type"]=="Unknown"){ I have also used : if(strcmp($Conf[0]["Type],"Unknown")<>0){ Link to comment https://forums.phpfreaks.com/topic/120239-solved-undefined-offset-0/#findComment-619407 Share on other sites More sharing options...
uniflare Posted August 18, 2008 Share Posted August 18, 2008 use this to debug the problem: print_r($Conf); Then "View Source" of the resulting page and print it here (you may find the answer yourself while browsing the results) Link to comment https://forums.phpfreaks.com/topic/120239-solved-undefined-offset-0/#findComment-619409 Share on other sites More sharing options...
jrm Posted August 18, 2008 Author Share Posted August 18, 2008 Why do I have only one record? Array ( [10] => Array ( [Type] => Room Conf [DTG_Start] => 1202253600 [DTG_End] => 1202315520 [Approved] => Counselor Montalvo, G [Total] => 17hrs, 12mins ) ) Link to comment https://forums.phpfreaks.com/topic/120239-solved-undefined-offset-0/#findComment-619414 Share on other sites More sharing options...
uniflare Posted August 18, 2008 Share Posted August 18, 2008 ok found the problem. Whenever you Assign a variable in a loop, only the Last assignment will be held (because each successive assignment overwrites the last. this code: <?php $Conf = array($ConfCtr => array("Type" => $Type, "DTG_Start" => strtotime($ConfRow["DTG_Start"]), "DTG_End" => strtotime($ConfRow["DTG_End"]), "Approved" => $ApprovedBy, "Total" => $hours . "hrs, " . $minutes . "mins")); $ConfCtr++; ?> $Conf is getting overwritten. there are two resolutions: 1. <?php $Conf[] = array("Type" => $Type, "DTG_Start" => strtotime($ConfRow["DTG_Start"]), "DTG_End" => strtotime($ConfRow["DTG_End"]), "Approved" => $ApprovedBy, "Total" => $hours . "hrs, " . $minutes . "mins"); ?> or 2. <?php $Conf[$ConfCtr] = array("Type" => $Type, "DTG_Start" => strtotime($ConfRow["DTG_Start"]), "DTG_End" => strtotime($ConfRow["DTG_End"]), "Approved" => $ApprovedBy, "Total" => $hours . "hrs, " . $minutes . "mins"); $ConfCtr++; ?> ----------------------- Hope this helps. Happy coding Link to comment https://forums.phpfreaks.com/topic/120239-solved-undefined-offset-0/#findComment-619420 Share on other sites More sharing options...
jrm Posted August 18, 2008 Author Share Posted August 18, 2008 Ah, ha, said the blind man urinating into the wind. Link to comment https://forums.phpfreaks.com/topic/120239-solved-undefined-offset-0/#findComment-619424 Share on other sites More sharing options...
jrm Posted August 19, 2008 Author Share Posted August 19, 2008 Ok, these arrays are kicking me in the rear, with spiked boots. And I know that it is a simple fix, a bracket or brace that is out of place, but where?!?!?!?!?!?!?!?!?!?!?!?!??!!?!?!?!?!?! my code: function StaffTraining($tStaffID, $tTJPCCertDate) { include "Connection.php"; $TwoYears = 60*60*224*730; $CertSubmitQuery = "Select Max(DTG) as CertSubmit From Staff_be.StaffDates Where SDID = 10 and StaffID = " . $tStaffID . ";"; $CertSubmitResults = mysql_query($CertSubmitQuery, $link) or die("\n<p> Could not run CertSubmitQuery : " . $CertSubmitQuery . " : " . mysql_error()); while($CertSubmitRow = mysql_fetch_array($CertSubmitResults, MYSQL_ASSOC)) { $CertSubmit = strtotime($CertSubmitRow["CertSubmit"]); } $NextCert = date("Ymd" , $tTJPCCertDate + $TwoYears); $tCertSubmit = date("Ymd", $CertSubmit); $TrainingQuery = "SELECT TrnCrsID, DTG, Instructor, Memo from Training_be.Training where StaffID = " . $tStaffID . " and DTG >= '" .$tCertSubmit . "' and DTG <= '" . $NextCert ."' Order by DTG;"; $TrainingResults = mysql_query($TrainingQuery, $link) or die("\n<p> Could not run TrainingQuery : " . $TrainingQuery . " : " . mysql_error()); if(mysql_num_rows($TrainingResults)==0) { $Topics[0] = array("Title" => "Unknown", "Level" => 0); // no code yet $Courses[0] = array("Course" => "N/A or Unknown", "DTG" => "Unknown", "Instructor" => "Unknown", "Memo" => "Unknown", "Hours" => 0); } else { $CourseCounter = 0; while($TrainingRow = mysql_fetch_array($TrainingResults, MYSQL_ASSOC)) { $DTG = strtotime($TrainingRow["DTG"]); $Instructor = $TrainingRow["Instructor"]; $Memo = $TrainingRow["Memo"]; $Topics[0] = array("Title" => "", "Level" => 0); // no code yet $CourseQuery = "Select Topic, Level, Hours From Training_be.TrainingCourses Where TrnCrsID = ". $TrainingRow["TrnCrsID"] ." Order by Level;"; $CourseResults = mysql_query($CourseQuery, $link) or die("\n<p> Could not run CourseQuery : " . $CourseQuery . " : " . mysql_error()); while($Courses = mysql_fetch_array($CourseResults, MYSQL_ASSOC)) { $Title = $Courses["Topic"]; $Level = (int) $Courses["Level"]; $Hours = $Courses["Hours"]; //echo "\n<p>" . $Title ." - " . $Level . " - " . $Hours; } $Courses[$CourseCounter] = array("Course" => $Title , "DTG" => $DTG , "Instructor" => $Instructor , "Memo" => $Memo , "Hours" => $Hours ); $CourseCounter++; } } return $Courses; } Output: There is suppose to be 18 Array ( [0] => Array ( [Course] => Emergency Action Plan [DTG] => 1214283600 [instructor] => M. Varela [Memo] => [Hours] => 2.00 ) ) Link to comment https://forums.phpfreaks.com/topic/120239-solved-undefined-offset-0/#findComment-620420 Share on other sites More sharing options...
jrm Posted August 19, 2008 Author Share Posted August 19, 2008 Never mind. I just made individual functions for everything. Link to comment https://forums.phpfreaks.com/topic/120239-solved-undefined-offset-0/#findComment-620471 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.