473,396 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Output multiple query result in csv

Hi,

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"); ?>
<?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).";";
$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

Thanks
Nov 2 '11 #1
0 1000

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

Similar topics

2
by: Joe Gazda | last post by:
I'm a relative newbie to PHP, but have been able to put together some PHP code to generate a CSV/XLS file from a Query result. Now, I would like to include custom column names instead of the MySQL...
2
by: Wei Wang | last post by:
Hi, I want to do a select in dynamic command, something like: TRIGGER FUNCTION DECLARE table_name_suffix text; temp_result RECORD; temp_result2 RECORD;
2
by: Martin Sarsale | last post by:
Dear All: Im looking for solutions (Free Software is better) to do query result caching. Thanks to the people from #postgresql I know that postgres doesn't do that by himself and the solution...
1
by: RookieDan | last post by:
Greetings fellow Accessers! Im new but in Access, but I have some background in different coding. I have a programme loading customer data into Access belonging to BMW dealers in Europe. ...
2
ntxsoft
by: ntxsoft | last post by:
Hello everybody, I have a problem while I am trying to execute multiple query in a statement. My query like that DROP TABLE IF EXISTS query; CREATE TEMPORARY TABLE query SELECT...
1
ddtpmyra
by: ddtpmyra | last post by:
how can I capture the query result in PHP? I have two queries below: # Fetch the file information $query ="update filestorage set approved ='Y' where FileID = {$id}"; $query1 ="select...
2
by: reeba | last post by:
I want to store the query result, in an servlet, into an xml file and display the contents of the xml file on the browser...... my code is as follows: public void doPost(HttpServletRequest...
1
by: titli | last post by:
Hi Friends, I have some code in an already built application. Now the output pivots in .xls files is not matching with input data. The output .xls has summarized results whereas , the input...
25
by: NDayave | last post by:
How do, I have a form that outputs addresses in a format that can be printed on to 3x7 label paper for envelopes. What I want is a way to enter blank (or " ") rows to the query result where the...
0
by: Jason C | last post by:
I've got a simple database in Access 2007 with a form interface. One of the forms contains subforms and uses multiple tables, currently navigation works fine. There's also several complex queries...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.