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
Bookmarks