Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2011
    Location
    California
    Posts
    63
    Plugin Contributions
    0

    Default Orders Table CSV MYSQL ?

    This script exports and creates a CSV file from the orders table.
    You can select to export orders by orders status and by shipping code.


    What I having problems with is I want to add the products weight, name and model number to the
    CSV file, this data is in 2 different tables (ORDERS_PRODUCTS) and (PRODUCTS)

    The data comes from the (orders_products table) and the weight comes from the (products table)

    | ORDERS |
    orders_id

    | ORDERS_PRODUCTS |
    search records by: orders.orders_id
    get the products id by: orders_products.products_id
    get the products name and model number from this table

    | PRODUCTS |
    get the products weight. the products id is taken from
    (orders_products.products_id) then the
    products_weight can be returned.

    I don’t know what my sql_query should look like and I don’t know how to add these fields to my
    CSV file.

    Here is the code and a screen shot of the application.
    Currently the script is a standalone. I will incorporate it in Zen-cart after I get it working like I want it to.

    Code:
    <!--START Webstar PHP --> <?php
    	// status is a number for the status of the order, Pending 1, Processing 2, Delivered 4, Update 3
    		    $status = '2';
    	// if the submit button is clicked run 
    			if(isset($_POST['submit'])){
    	        //database conn host,usr,pass
    			$conn = mysql_connect("host name","user name","pass word")or die('Could not connect to database '.mysql_error());
    			//database name
    			mysql_select_db("database name",$conn);
    			//end datbase conn
    			$shipit = $_POST['shiper'];
    			$status = $_POST['status'];
    			 
    	// file name and the directory for the csv file
    			$filename = 'link to csv file';
    
     $sql = mysql_query("SELECT * FROM orders WHERE orders_status = $status And shipping_module_code = '$shipit' ")or die('Something went wrong: '.mysql_error());
     
     //make coloum headers with names
    
    			$num_rows = mysql_num_rows($sql);
    
    			if ($num_rows >=1)
    			{
    			$row = mysql_fetch_assoc($sql);
    			$fp = fopen($filename,"w");
    			$seperator ="";
    			$comma ="";
    
    			foreach($row as $name => $value)
    			{
    			$seperator .= $comma . '' .str_replace('','""',$name);
    			$comma = ",";
    			}
    			 $seperator .= "\n";
    														
    			//echo $seperator;
    
                 fputs($fp,$seperator);
    
     //make the data values
                 mysql_data_seek($sql, 0);
    
                 while ($row = mysql_fetch_assoc($sql))
                {
    			$seperator ="";
    			$comma ="";
    
    			foreach($row as $name => $value)
    			{
    			$seperator .= $comma . '' .str_replace('','""',$value);
    			$comma = ",";
    			}
    			$seperator .= "\n";
    			fputs($fp,$seperator);
    			}
    			showexport();
    
    	     if($seperator !=""){echo '<br/>Export Complete<b> '.$num_rows.' customers orders exported</b>';}
    
    			fclose ($fp);
    														
    			}
    			else
    			{
    			echo '<b style="color:red;">No Data Found To Export</b>';
    			}
    
    			}			if (isset($_POST['viewcsv'])){showexport();}
    			?>	<!--END Webstar PHP -->


    I hope you can understand my question, I kind of lost myself after posting this LOL

  2. #2
    Join Date
    Jun 2011
    Location
    California
    Posts
    63
    Plugin Contributions
    0

    Default Re: Orders Table CSV MYSQL ?

    heres a query that gets the data but how can i add the fields to each record in the csv file

    Code:
     
    $yoy = $row['orders_id'];
     $sqlWeight = mysql_query("SELECT products.products_weight,orders_products.orders_id FROM products, orders_products WHERE products.products_id = orders_products.products_id AND orders_products.orders_id = $yoy ")or die('yoyo wrong: '.mysql_error());
      $roweight = mysql_fetch_assoc($sqlWeight); echo $roweight['products_weight'];
    Last edited by webstar59; 3 Nov 2011 at 07:17 PM.

 

 

Similar Threads

  1. Import Customers From CSV Via MySql?
    By suntower in forum Managing Customers and Orders
    Replies: 6
    Last Post: 15 Jun 2011, 06:54 AM
  2. Batch product updates, importing .csv to MySQL
    By jdw1979 in forum Setting Up Categories, Products, Attributes
    Replies: 10
    Last Post: 30 Apr 2011, 04:45 PM
  3. zen_products csv table update in phpmyadmin
    By Webgremlin in forum General Questions
    Replies: 0
    Last Post: 16 Nov 2009, 03:35 AM
  4. problems importing to mysql from .csv - products not showing
    By TXMagnum in forum General Questions
    Replies: 1
    Last Post: 29 Jan 2008, 05:23 PM
  5. Need help importing customers database from csv file into mySQL
    By jeffmic in forum Managing Customers and Orders
    Replies: 18
    Last Post: 20 Jan 2008, 04:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR