Darrennew
asked on
Joining three tables and export to csv file
I am trying to modify a osc script to export to sage all works fine but know i have created a new table to hold the default data for sage now i need to be able to select the extra data and export to csv see below i am still learning php so i am lost.
Script so far:
-------------------------- ---------- ---------- ---
<?php
require('includes/applicat ion_top.ph p');
if (!$HTTP_GET_VARS['submit'] )
{
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//DE">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet. css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#CCCC33">
<!-- header //-->
<?php require(DIR_WS_INCLUDES.'h eader.php' ); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2" >
<tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES.'c olumn_left .php'); ?>
<!-- left_navigation_eof //-->
</table></td><td>
<!-- body_text //-->
<?php
echo "Export and Save Customer Data onto your Local Machine";
echo '<form action="'. $phpself.'">';
echo '<input type="submit" value="Export Customer Shipping Info" name="submit"></form>';
?>
</td>
</table>
<!-- footer //-->
<center><font color="#666666" size="2"></font></center>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php
}
else
{
$contents="Customer_id,Cus tomer Name,Address Line 1,Address Line 2,City,County,Zip,Name,Pho ne,Fax,Ana lyis 1,Analyis 2,Analyis 3,Dept_No,Vat_No,MTD,YTD,P rior YTD,Credit Limit,Terms,Due Days,Discount Rate,Nominal Code,Tax Code,Trade Contact,Tel 2,Website,Email\n";
$user_query = mysql_query('select c.*, adb.* from customers as c left join address_book as adb on c.customers_id = adb.customers_id');
while($row = mysql_fetch_array($user_qu ery))
{
//took out the references to gender
if ($row[entry_country_id] == 81)
{
$land="Deutschland";
}
else
{
$country_query = mysql_query("select countries_name from countries where countries_id = '" . $row[entry_country_id] . "';");
$landq = mysql_fetch_array($country _query);
$land=$landq[countries_nam e];
}
// Getting the county name from the zone_id
$zone_query = mysql_query("select zone_name from zones where zone_id = '" . $row[entry_zone_id] . "';");
$zoneq = mysql_fetch_array($zone_qu ery);
$zone = $zoneq[zone_name];
//reordered the city and zipcode and added suburb or address line 2
// and the county...
$contents.=$row[customers_ id].",";
$contents.=$row [customers_lastname].",";
$contents.=$row[entry_stre et_address ].",";
$contents.=$row[entry_subu rb].",";
$contents.=$row[entry_city ].",";
$contents.=$zone.",";
$contents.=$row[entry_post code].",";
$contents.=$row [customers_firstname].",";
$contents.=$row[customers_ telephone] .",";
$contents.=$row[customers_ fax].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [customers_group_name]."," ;
$contents.=$row [sage_tax_code].",";
$contents.=$row [customers_firstname].",";
$contents.=$row[customers_ telephone] .",";
$contents.=$row[customers_ email_addr ess].",";
$contents.=$row[na].",";
$contents.=$row[entry_stat e]."\n";
}
Header("Content-Dispositio n: attachment; filename=SageExport_custom ers.csv");
print $contents;
}
require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
-------------------------- ---------- -end of script
i think i am on the right path i need to join table name sage to the query i think this part of the code needs tobe modified but i don't know.
Part of code--------
$user_query = mysql_query('select c.*, adb.* from customers as c left join address_book as adb on c.customers_id = adb.customers_id');
-------------------------- ---------- ---------- ---------- ---------- ---------- ---
do i join the sage table here and if so how would i join the extra sage table.
many thanks
Darren
Script so far:
--------------------------
<?php
require('includes/applicat
if (!$HTTP_GET_VARS['submit']
{
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//DE">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#CCCC33">
<!-- header //-->
<?php require(DIR_WS_INCLUDES.'h
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2" >
<tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES.'c
<!-- left_navigation_eof //-->
</table></td><td>
<!-- body_text //-->
<?php
echo "Export and Save Customer Data onto your Local Machine";
echo '<form action="'. $phpself.'">';
echo '<input type="submit" value="Export Customer Shipping Info" name="submit"></form>';
?>
</td>
</table>
<!-- footer //-->
<center><font color="#666666" size="2"></font></center>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php
}
else
{
$contents="Customer_id,Cus
$user_query = mysql_query('select c.*, adb.* from customers as c left join address_book as adb on c.customers_id = adb.customers_id');
while($row = mysql_fetch_array($user_qu
{
//took out the references to gender
if ($row[entry_country_id] == 81)
{
$land="Deutschland";
}
else
{
$country_query = mysql_query("select countries_name from countries where countries_id = '" . $row[entry_country_id] . "';");
$landq = mysql_fetch_array($country
$land=$landq[countries_nam
}
// Getting the county name from the zone_id
$zone_query = mysql_query("select zone_name from zones where zone_id = '" . $row[entry_zone_id] . "';");
$zoneq = mysql_fetch_array($zone_qu
$zone = $zoneq[zone_name];
//reordered the city and zipcode and added suburb or address line 2
// and the county...
$contents.=$row[customers_
$contents.=$row [customers_lastname].",";
$contents.=$row[entry_stre
$contents.=$row[entry_subu
$contents.=$row[entry_city
$contents.=$zone.",";
$contents.=$row[entry_post
$contents.=$row [customers_firstname].",";
$contents.=$row[customers_
$contents.=$row[customers_
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [na].",";
$contents.=$row [customers_group_name].","
$contents.=$row [sage_tax_code].",";
$contents.=$row [customers_firstname].",";
$contents.=$row[customers_
$contents.=$row[customers_
$contents.=$row[na].",";
$contents.=$row[entry_stat
}
Header("Content-Dispositio
print $contents;
}
require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
--------------------------
i think i am on the right path i need to join table name sage to the query i think this part of the code needs tobe modified but i don't know.
Part of code--------
$user_query = mysql_query('select c.*, adb.* from customers as c left join address_book as adb on c.customers_id = adb.customers_id');
--------------------------
do i join the sage table here and if so how would i join the extra sage table.
many thanks
Darren
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: misslesilo
Any objections should be posted here in the next 4 days. After that time, the question will be closed.
- Neester -
EE Cleanup Volunteer