In my PHP code for generating a report in excel sheet, I have the following two queries.
Code: Select all
$orders = func_query("SELECT $sql_tbl[order_details].productid, $sql_tbl[order_details].product_options, avail, $sql_tbl[orders].date, count($sql_tbl[order_details].productid )
FROM $sql_tbl[order_details],$sql_tbl[products],$sql_tbl[orders]
WHERE $sql_tbl[order_details].productid =$prod_code
AND $sql_tbl[order_details].productid = $sql_tbl[products].productid
AND $sql_tbl[order_details].orderid = $sql_tbl[orders].orderid
AND $sql_tbl[orders].date <$large_number
AND $sql_tbl[orders].date >$small_number
GROUP BY product_options");
$countsold=func_query("select count($sql_tbl[order_details].productid)
FROM $sql_tbl[order_details],$sql_tbl[products],$sql_tbl[orders]
WHERE $sql_tbl[order_details].productid =$prod_code
AND $sql_tbl[order_details].productid = $sql_tbl[products].productid
AND $sql_tbl[order_details].orderid = $sql_tbl[orders].orderid
AND $sql_tbl[orders].date <$large_number
AND $sql_tbl[orders].date >$small_number GROUP BY product_options");
For writing the results of the first query in excel, I am using the following code which works fine.
foreach ($orders as $value) {
$filename ="Report.xls";
$export_file = "/home/expressi/public_html/store/admin/".$filename;
$fp=fopen($export_file,"wb");
fwrite($fp,$value["productid"]);
fwrite($fp,$value["product_options"]);
}
However, for displaying the results of the second query, I am facing a problem with the following code
for ( $cnt1 = 1; $cnt1 <= count($countsold) ; $cnt1 += 1) {
fwrite($fp,"'$countsold[$cnt1][count($sql_tbl[order_details].productid)]'");
}