Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are three problems:</p> <ol> <li>The onclick expects JavaScript, you just give it an URL. Maybe try it with a small form?</li> <li>The <code>$file_array</code> is a <a href="http://www.php.net/manual/en/pdostatement.fetch.php" rel="nofollow">PDOStatement</a> and you have to fetch the data first by <a href="http://www.php.net/manual/en/pdostatement.fetchall.php" rel="nofollow">fetchAll()</a> or <a href="http://www.php.net/manual/en/pdostatement.fetch.php" rel="nofollow">fetch()</a> and then encode it with <a href="http://de2.php.net/manual/en/function.json-encode.php" rel="nofollow">json_encode()</a> and <a href="http://de2.php.net/manual/en/function.htmlspecialchars.php" rel="nofollow">htmlspecialchars()</a>.</li> <li>The <code>foreach</code> has a wrong format.</li> </ol> <p>Try the following:</p> <pre> &lt;?php $file_array=$db->prepare("SELECT UserID, UserName FROM UserProfile"); $file_array->execute(); ?&gt; &lt;form method="POST" action="download_file.php"&gt; &lt;input type="hidden" name="pass_array" value="&lt;?php echo htmlspecialchars(json_encode($file_array-&gt;fetchAll(PDO::FETCH_NUM)); ?&gt;"&gt; &lt;input type="submit"&gt; &lt;/form&gt; </pre> <p>To get the data in the <code>download_file.php</code>:</p> <pre> function output_csv ($data) { $filename = "exportfile.csv"; $handle = fopen($filename, 'w+'); fputcsv($handle, array('UserID','UserName')); foreach($data as $row) { fputcsv($handle, $row); } fclose($handle); } $file_array = json_decode($_REQUEST['pass_array']); output_csv($file_array); </pre> <p>Another benefit of the post form is that the data will be transferred in an invisible way. So you don't see really long and strange URLs in the browser. Also the amount of data that could be transferred is a lot higher.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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