Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Export MySQL to CSV - Results showing HTML
    primarykey
    data
    text
    <p>I saw a post on this already, but it didn't really provide a solution (that has worked for me at least)...</p> <p>I have a PHP page that does some basic MySQL queries, the results of which are displayed on the page. I'm using some $_GET and $_SESSION variables throughout this process.</p> <p>In the same page, I also allow the user to "Export to CSV" (by calling a function). The file returned from the export has the CSV results at the bottom, but also contains the HTML of my page (which calls the function). </p> <p>Now, at the top of the page I have ob_start() and at the bottom I have ob_flush(), otherwise on page load I will receive some "Cannot modify header..." errors. So, as suggested in the post that I read:</p> <pre><code> My guess is that you've got some sort of template that generates the same HTML header and footer regardless of the page that is requested. Sometime before the exportCSV function is called, the header is generated. You don't show the bottom of the output, but I'll bet the footer is there too, since I suspect the flow control will continue on to that code after the function exits." (http://stackoverflow.com/questions/207019/why-am-i-getting-html-in-my-mysql-export-to-csv/207046) </code></pre> <p>Does anyone have any ideas on how I can prevent this from happening? Let me know if I should post some of my code and I will...</p> <p>Thanks!</p> <p>EDIT:</p> <p>When calling ob_end_clean() before I call my export function, it gets rid of any html before the CSV. However, I am still getting some HTML closing tags after the CSV results...</p> <pre><code> fname lname MONTH WeekdayCount WeekendCount John Doe 8 1 0 John Doe 7 3 2 Jane Smith 7 3 2 &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>EDIT:</p> <p>This issue has been solved by calling exit() after calling the CSV export script. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload