troubleshooting Question

Joining three tables and export to csv file

Avatar of Darrennew
Darrennew asked on
2 Comments1 Solution207 ViewsLast Modified:
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:
if (!$HTTP_GET_VARS['submit'])
      <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//DE">
      <html <?php echo HTML_PARAMS; ?>>
      <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">
      <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" >
          <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 //-->
      <!-- body_text //-->

      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>';
      <!-- footer //-->
      <center><font color="#666666" size="2"></font></center>
      <!-- footer_eof //-->

      $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)
                  $country_query = mysql_query("select countries_name from countries where countries_id = '" . $row[entry_country_id] . "';");
                  $landq = mysql_fetch_array($country_query);

            // 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_lastname].",";
            $contents.=$row [customers_firstname].",";
            $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].",";
      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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros