I am making an online shopping site in PHP & My SQL where I need to fetch records of orders placed during last 5 days. The table name is “orders” with fields (Order_ID, Customer_ID, Total_Amount, Shippinig_Status, Order_Date)
Can anybody help me that what should be my SQL query to fetch records of orders placed in last 5 days ?
$date = date('Y-m-d H:i:s',time()-(5*86400));
$sql = "SELECT * FROM orders WHERE Order_Date<='$date' ";
Try that out - no promises it works. Partially made from me searching google and me trying to read this SQL Sitepoint book I got recently…100% sure that there is a better method that someone will correct me…
I want to Generate serial number in mysql query with auto-increment .
My query is as follows -
set @a:=0;select @a:=@a+1 serial_number, b.Prod_ID, b.Product_Name, sum(t.Quantity) as transactionamount, sum(t.Quantity)*t.Price
from products b
left join order_details t on t.Prod_ID = b.Prod_ID
group by b.Prod_ID, b.Product_Name order by serial_number ASC
When I am running it directly in phpMyAdmin, its displaying the results properly but when I am using it in PHP code than its giving error as below -
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\shopping\try.php on line 9
That error means that the query has failed. Echo the query and check what you’re sending to mysql. btw, are you aware that the old mysql_* extension has been deprecated as of version 5.5 of PHP?