Hi,
Can you please help me with the following code?
This function has to generate a report to an excel sheet on execution. But when I click on the excel icon, a report is generate from the DB but I don’t get the referral name section, instead it shows “Yes” in all referral name field. It is showing in the DB though…
This was done for another registration table, but I copied an used it for one more table which I created. I’m a newbie, I couldn’t get help from the one who initially done this for us.
<?php ob_start(); /* ** include Connection ** */ include_once "connection.php"; $sql = "SELECT `camp_id`, `friend_name`, `friend_email`, `u_name`, `u_email` FROM event_forward_list WHERE camp_id='{$_REQUEST['camp_id']}'"; $result = @mysql_query($sql) or die("Couldn't execute query:" . mysql_error(). "
" . mysql_errno()); $timestamp = date("Ymd-His"); header("Content-Type: application/vnd.ms-excel"); //define header info for browser header("Content-Disposition: attachment; filename=Event_Forward_list{$timestamp}.xls"); header("Pragma: no-cache"); header("Expires: 0"); $sql_field_array = array( "camp_id" => "Camp ID", "friend_name" => "Name", "friend_email" => "Email", "u_name" => "Referral Name", "u_email" => "Referral Email", ); for ($i = 0; $i < mysql_num_fields($result); $i++) // show column names as names of MySQL fields echo $sql_field_array[mysql_field_name($result,$i)] . "\t"; print("\n"); while($row = mysql_fetch_row($result)) { //set_time_limit(60); // you can enable this if you have lo of data $schema_insert = ""; $totalRows = mysql_num_fields($result); for($j=0; $j< $totalRows;$j++) { if(!isset($row[$j])) $schema_insert .= "NULL\t"; elseif ($row[$j]){ if(($totalRows-2)==$j){ /* Subscription Checkbox */ $schema_insert .=($row[$j]?"Yes\t":"No\t"); }else{ $schema_insert .= "$row[$j]\t"; } }else $schema_insert .= "\t"; } $schema_insert = str_replace("$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } ?>
Your help is highly appreciated!!!
Thanks,