dougp25
09-09-2007, 10:11 AM
Hi All.
I am using a script from the PHP Cookbook by O'Reilly, but having some issues. Basically when I run the script, I get this error in the browser window:
Warning: fputcsv() expects parameter 2 to be array
When I paste my query in phpMyAdmin, I get back roughly 100 rows of data, so I know the query is good. I guess I need to somehow convert the query to an array?? Here is my code so far (the query is long and nested and ugly, so most of it can be ignored!) (I should mention that I use a class called ez_sql to perform my queries, but I'm not against doing is some other way!)
$sSQL="SELECT studentbio.studentbio_id,
studentbio.studentbio_lname, studentbio.studentbio_fname,
school_names.school_names_desc, grades.grades_desc FROM ((studentbio
INNER
JOIN student_grade_year ON studentbio.studentbio_id =
student_grade_year.student_grade_year_student) INNER JOIN school_names
ON
studentbio.studentbio_school = school_names.school_names_id) INNER JOIN
grades ON student_grade_year.student_grade_year_grade = grades.grades_id
ORDER BY
studentbio.studentbio_lname";
$student_data=$db->get_results($sSQL);
$output=fopen('php://output','w') or die("Can't open php://output");
//Print header row
fputcsv($output,array('StudentID','LastName','FirstName','School','Grade'));
foreach($student_data as $student_line) {
fputcsv($output, $student_line);
$total += $student_line[3];
}
?>
Thanks for any help!
I am using a script from the PHP Cookbook by O'Reilly, but having some issues. Basically when I run the script, I get this error in the browser window:
Warning: fputcsv() expects parameter 2 to be array
When I paste my query in phpMyAdmin, I get back roughly 100 rows of data, so I know the query is good. I guess I need to somehow convert the query to an array?? Here is my code so far (the query is long and nested and ugly, so most of it can be ignored!) (I should mention that I use a class called ez_sql to perform my queries, but I'm not against doing is some other way!)
$sSQL="SELECT studentbio.studentbio_id,
studentbio.studentbio_lname, studentbio.studentbio_fname,
school_names.school_names_desc, grades.grades_desc FROM ((studentbio
INNER
JOIN student_grade_year ON studentbio.studentbio_id =
student_grade_year.student_grade_year_student) INNER JOIN school_names
ON
studentbio.studentbio_school = school_names.school_names_id) INNER JOIN
grades ON student_grade_year.student_grade_year_grade = grades.grades_id
ORDER BY
studentbio.studentbio_lname";
$student_data=$db->get_results($sSQL);
$output=fopen('php://output','w') or die("Can't open php://output");
//Print header row
fputcsv($output,array('StudentID','LastName','FirstName','School','Grade'));
foreach($student_data as $student_line) {
fputcsv($output, $student_line);
$total += $student_line[3];
}
?>
Thanks for any help!
