Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql give different result if I download it
    text
    copied!<p>I am using PHP and MySQL to run a query, I have written two scripts having same query, but one for displaying the query result on browser and other for downloading the query result as a file. Even though its the same query, its giving different result while downloading, which is incorrect. My query for instance is </p> <pre><code>$query="select * from tf where gene_symbol like '%$sterm%' || gene_name like '%$sterm%' || synonym like '%$sterm%'"; </code></pre> <p>If <code>$sterm</code> is <strong>ZINC FINGER PROTEIN</strong>, it give 685 records both on mysql command line and display. But if I download the file it give around 800 records by adding even the records <code>where gene_name like '%ZINC FINGER%'</code></p> <p>Does anyone have any idea, what could be causing it. Thanks in advance. Konika</p> <p>Here is the code for downloading the file </p> <pre><code>&lt;?php $sterm = $_POST["sterm"]; $sterm = strtoupper($sterm); $query = "select * from tf where gene_symbol like '%$sterm%' || gene_name like '%$sterm%' || synonym like '%$sterm%'"; $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) &gt; 0) { result_disp($result); } function result_disp($results) { $num_fields = mysql_num_fields($results); $headers = array(); for ($i = 0; $i &lt; $num_fields; $i++) { $headers[] = mysql_field_name($results, $i); } $fp = fopen('php://output', 'w'); if ($fp &amp;&amp; $results) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="export.txt"'); header('Pragma: no-cache'); header('Expires: 0'); fputcsv($fp, $headers, chr(9)); while ($rows = mysql_fetch_row($results)) { fputcsv($fp, array_values($rows), chr(9)); } die; } } fclose($fp); ?&gt; </code></pre>
 

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