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);