By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,096 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

Output multiple query result in csv

P: 1

I'm trying to export the result of 2 different mysqlquery from 2 different database on the same server with the same user and password.

I'm sure i'm pretty close but it does not output any result. Here my sample code:

<?php include("/home/decpromo/public_html/admin/login.php"); ?>
// establish database connection
$handle_db1 = mysql_connect("localhost","user","pw", "true");
$handle_db2 = mysql_connect("localhost","user","pw", "true");

mysql_select_db( "db1", $handle_db1 ) or die( mysql_error( $handle_db1 ) );
mysql_select_db( "db2", $handle_db2 ) or die( mysql_error( $handle_db1 ) );

$resQuery = 'SELECT column1,column2,column3,column,FROM table1, table2 WHERE table1.column1 = othertable.other clumn'; $which = $handle_db1; mysql_query($resQuery,$which);

$resQuery = 'SELECT column1,column2,column3,column,FROM table1, table2 WHERE table1.column1 = othertable.other clumn'; $which = $handle_db1; mysql_query($resQuery,$which);$which = $handle_db2; mysql_query($resQuery,$which);

// Liste les données de la table
// -------------------------------------------

header("Content-Type: application/csv-tab-delimited-table");
header("Content-disposition: filename=table.csv");

if (mysql_num_rows($resQuery) != 0) {

// titre des colonnes
$fields = mysql_num_fields($resQuery);
$i = 0;
while ($i < $fields) {
echo mysql_field_name($resQuery, $i).";";
echo "\n";

// données de la table
while ($arrSelect = mysql_fetch_array($resQuery, MYSQL_ASSOC)) {
foreach($arrSelect as $elem) {
echo "$elem;";
echo "\n";


Any clue

Nov 2 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.