MySQL Forums
Forum List  »  PHP

How do I make all columns line up in the same row?
Posted by: Dane Iracleous
Date: March 12, 2006 11:13PM

I am exporting data from the mysql database into a csv file and I want the data to line up. I have different tables, each containing certain values. For example, my customer table contains first name, last name, address, etc. and my item table contains item number, shipping, etc....however, each value corresponds to other values. The thing, is they are separated by tables. I want each value to line up correctly with the next in the same row.

Here is the code Im using right now which does not line things up in the same row and in fact creates 3 separate rows for 3 separate tables. I want the data from these 3 tables to line up in 1 row.


$fp = fopen('csvdir/formdata.csv','w'); 
$q = 'select * from customer'; 
$query = mysql_query($q); 
while ($row = mysql_fetch_array($query)) { 
$nextline = $row[0] . ',' . $row[1] . ',' . $row[2] . ',' . $row[3] . ',' . $row[4] . ',' . $row[5] . ',' . $row[6] . ',' . $row[7] . ',' . $row[8] . ',' . $row[9] . ',' . $row[10] . "\r\n";  
fwrite($fp,$nextline); 
}
$q = 'select * from orders'; 
$query = mysql_query($q); 
while ($row = mysql_fetch_array($query)) { 
$nextline = $row[0] . ',' . $row[1] . ',' . $row[1] . ',' . $row[3] . ',' . $row[4] . ',' . $row[7] . ',' . $row[8] . ',' . $row[9] . ',' . $row[10] . ',' . $row[11] . "\r\n"; 
fwrite($fp,$nextline); 
} 
$q = 'select * from item'; 
$query = mysql_query($q); 
while ($row = mysql_fetch_array($query)) { 
$nextline = $row[1] . ',' . $row[2] . ',' . $row[3] . ',' . $row[4] . "\r\n"; 
fwrite($fp,$nextline); 
} 
 
fclose($fp); 


Options: ReplyQuote


Subject
Written By
Posted
How do I make all columns line up in the same row?
March 12, 2006 11:13PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.