Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your original code was querying each of the checkboxed IDs individually (a long and laborious way to handle it) and was trying to dump the results individually per row (not going to work well for you).</p> <p>Try this. (<strong>NOTE: Untested, but should give you a good starting point to develop.</strong>)</p> <pre><code>if( $_POST['exporttxt'] ){ if( count( $_POST['checkbox'] )&gt;0 ){ // If the checkbox values are meant to all be integers, you might want to perform some validation/sanitisation/filtering here // Up to you to do that // Collapse the IDs from the checkboxes into a comma-delimited string $export_ids = implode( ',' , $_POST['checkbox'] ); // Template the SQL Query $sqlTpl = 'SELECT code FROM ticket WHERE id IN ( %s )'; // Compile the SQL Query String $sqlStr = sprintf( $sqlTpl , $export_ids ); // Execute the SQL Query if( !( $sqlRes = mysql_query( $sqlStr ) ) ){ // SQL Error - Log it, Handle it }elseif( mysql_num_rows( $sqlRes )==0) { // No Rows Returned - Log it, Handle it }else{ // We have results - process them $text = array(); while( $r = mysql_fetch_assoc( $sqlRes ) ){ // Looping through the returned rows, adding them to the $text array $text[] = $r['code']; } // Collapse the $text array down into a normal string, with one element per line $output = implode( "\n" , $text ); // Output Handling from @narcisradu's answer header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Transfer-Encoding: binary;\n"); header("Content-Disposition: attachment; filename=\"filename.txt\";\n"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Description: File Transfer"); header("Content-Length: ".strlen($output).";\n"); echo $output; die; // Prevent any further output } }else{ // No Checkboxes Checked echo 'You must select one or more checkboxes to export something, muppet.'; } } </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