ghicks — 2012-08-27T16:33:46-04:00 — #1
I've been staring at this code for awhile now and can't seem to see what it is I've overlooked. I'm attempting to build an array out of a database query, all the data is returned just as I expect it to, but in trying to build the array to use later in the code to compile the results into a table my code instead dumps all the results to the screen on my webpage.
Any suggestions as to what I am missing would be greatly appreciated. Below is the code I am using to retrieve the data (that works perfectly) then populate the array. Instead of populating the array however it is just dumping to the browser.
// Run the query against the database and process the results
$EmpReportResult = mysqli_query($db_server, $SQLEmpReport) or die("Unable to request employee list: " . mysqli_error());
while ($EmpReportRow = mysqli_fetch_array($EmpReportResult))
// First concactenate the employee name to single variable
$FullName = $EmpReportRow['Last_Name'] . ", " . $EmpReportRow['First_Name'];
// Then build the employee array
$Emps = array(
'empnum' => $EmpReportRow['Employee_Number'],
'fullname' => $FullName,
'phone' => $EmpReportRow['Phone'],
'strate' => $EmpReportRow['ST_Rate'],
'otrate' => $EmpReportRow['OT_Rate'],
'dtrate' => $EmpReportRow['DT_Rate'],
'actualst' => $EmpReportRow['ActualST'],
'actualot' => $EmpReportRow['ActualOT'],
'actualdt' => $EmpReportRow['ActualDT']
kduv — 2012-08-27T16:45:58-04:00 — #2
What do you mean it's just "dumping it to the browser"? Are you seeing the actual code? How are you trying to build the table? How are you sending the results to the browser? Are you just doing a print_r()?
Also, it will make you code much more readable if you surround your PHP code in [ PHP ] and [ /PHP ] tags (minus the spaces).
ghicks — 2012-08-27T17:19:43-04:00 — #3
Thanks, I realized it wasn't this code that was causing the problem, but rather the function I use to apply the htmlspecialchars to data being output to the browser. I had recently updated my function so that it not only applied the htmlspecialchars but also automatically echo'd the value to the browser. I've resolved that and my page is operating as I expected now.
I will keep in mind your comment about wrapping my code in the future for legibility.