Link to home
Start Free TrialLog in
Avatar of Darrennew
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/application_top.php');
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.'header.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.'column_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,Customer Name,Address Line 1,Address Line 2,City,County,Zip,Name,Phone,Fax,Analyis 1,Analyis 2,Analyis 3,Dept_No,Vat_No,MTD,YTD,Prior 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_query))
      {
         //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_name];
            }

            // 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_query);
            $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_street_address].",";
            $contents.=$row[entry_suburb].",";
            $contents.=$row[entry_city].",";
            $contents.=$zone.",";
            $contents.=$row[entry_postcode].",";
            $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_address].",";
            $contents.=$row[na].",";
            $contents.=$row[entry_state]."\n";
      }
      Header("Content-Disposition: attachment; filename=SageExport_customers.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
ASKER CERTIFIED SOLUTION
Avatar of missilesilo
missilesilo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
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