php - Trying to print a report from SQL Database? -


trying generate report form data base exported excel file, keep getting 0 results when there data in database. can take @ code , let me know have wrong. code needs go server running php 5.4+ 4+

<?php //set date $date = date("m/d");  $course_report = $_post['course_report'];  $course_info = explode('~',$course_report); $course_info[0]; // course_id $course_info[1]; // course_date   $select = "select distinct * registrants (paid='y' , course_id = '$course_info[0]' , course_date = '$course_info[1]')"; $result = mysqli_query($dbc, $select);  // first header row while($row = mysqli_fetch_assoc($result)) {     $course = $row['course'];     $coursedate = $row['course_date'];      $export = mysql_query($select);     $fields = mysql_num_fields($export);  }  // header  $fields = isset($_post['fields']); ($i = 0; $i < $fields; $i++) {     $header .= mysqli_field_name($export, $i) . "\t"; }   // rows of data $export = isset($_post['export']); while($row = mysqli_fetch_row($result)) {     $line = '';     foreach($row $value) {                                                     if ((!isset($value)) or ($value == "")) {             $value = "\t";         } else {             $value = str_replace('"', '""', $value);             $value = '"' . $value . '"' . "\t";         }         $line .= $value;     }     $data .= trim($line)."\n"; } $data = isset($_post['data']); $data = str_replace("\r","",$data);   // check blank data set if ($data == "") {     $data = "\n(0) records found!\n";                         }  // end building data  $header = isset($_post['header']); $course = isset($_post['course']); $file_name = $course . "_downloaded_" . $date; header("content-type: application/x-msdownload"); //header("content-disposition: attachment; filename=registrar_101.txt"); header("content-disposition: attachment; filename=$file_name.xls"); header("pragma: no-cache"); header("expires: 0"); print "$header\n$data"; // }   ?>  

this says it's supposed 1 row, it's going all rows.

// first header row while($row = mysqli_fetch_assoc($result)) {     $course = $row['course'];     $coursedate = $row['course_date'];      $export = mysql_query($select);     $fields = mysql_num_fields($export);  } 

then each row you're inexplicably re-exectuing query mysql_query() , @ point i've stopped looking because need clean logic here if rest of script going make sense @ all.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -