will2002 Posted October 11, 2008 Share Posted October 11, 2008 hi I have an sql query which prints output to a html form. i then use header code to save the results of this as a microsoft excel document. All of the code is working fine. The only problem is that everything on the page is being saved in the excel file such as images, search fields, buttons etc. is there a way to just take the information from the query without the rest of the page coming aswell any help would be greatly appreciated. here is the section of code minus the html form and html table data, there is a lot of html code on the full page for navigation and visual purposes. hi I have an sql query which prints output to a html form. i wish to be able to send the results of this to a microsoft excel document. All of the code is working fine. The only problem is that everything on the page is being saved in the excel file such as images, search fields, buttons etc. is there a way to just take the information from the query without the rest of the page coming aswell any help would be greatly appreciated. here is the section of code minus the html form and html table data, there is a lot of html code on the full page for navigation and visual purposes. <?php ini_set('display_errors', 1); error_reporting(E_ALL & ~E_NOTICE); if(isset($_POST['login'])){ if($dbc = @mysql_connect('localhost', '', '')){ if(!$dbc = @mysql_select_db('employees')){ die("<p> Could not select the database because:'.mysql_error().'</p>"); } }else{ die("<p> Could not select the database because:'.mysql_error().'</p>"); } $query = "SELECT * FROM timesheet WHERE day='{$_POST['dt']}' AND month='{$_POST['month']}'AND year='{$_POST['year']}'"; if ($r = mysql_query($query)){ while ($row =mysql_fetch_array($r)){ echo "<tr><td>{$row['num']}</td><td>{$row['name']}</td><td>{$row['norm']}</td><td>{$row['normhalf']}</td><td>{$row['normdouble']}</td><td>{$row['normquarter']}</td><td>{$row['normthird']}</td><td>{$row['hol']}</td><td>{$row['hol1']}</td><td>{$row['hol2']}</td><td>{$row['hol3']}</td><td>{$row['remarks']}</td></tr>"; header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition:filename=file.xls"); ob_end_flush(); ?> Quote Link to comment Share on other sites More sharing options...
zq29 Posted October 12, 2008 Share Posted October 12, 2008 I'd recommend generating your Excel file in a separate script and linking to it... <?php header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition:filename=file.xls"); $r = mysql_query("SELECT * FROM `foo`") or die(mysql_error()); while($rr = mysql_fetch_assoc($r)) echo "\"$rr[foo_0]\",\"$rr[foo_1]\",\"$rr[foo_2]\"\n"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.