I have a series of SQL commands that result in the update of a table that I am currently displaying using a php page.
I would like to run a bunch of sql statements each time the page is loaded as there is a date field that is updated from time to time. Could somebody advise on the best way to do this?
- Do I include all the statements in the php code?, if so how.
- Do I create some kind of SQL function that I pass the date values to?, if so how.
Here is my current page code:
$sql = 'SELECT order_item_name, product_quantity,
order_number, category_name
FROM pvz8y_shopping_list';
I would like to include the following:
DROP TABLE pvz8y_shopping_list;
CREATE TABLE pvz8y_shopping_list (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
isle_number int(11),
category_name char(180),
virtuemart_product_id int(11),
virtuemart_category_id int(11),
order_item_name char(255),
product_quantity int(11),
order_number char(64),
PRIMARY KEY (id)
);
INSERT INTO pvz8y_shopping_list (virtuemart_product_id, order_item_name, product_quantity, order_number)
SELECT virtuemart_product_id, order_item_name, product_quantity,order_number from pvz8y_virtuemart_order_items
INNER JOIN pvz8y_virtuemart_orders
ON pvz8y_virtuemart_order_items.virtuemart_order_id = pvz8y_virtuemart_orders.virtuemart_order_id
WHERE pvz8y_virtuemart_orders.created_on **>= '2014-07-19 00:00:00' AND
pvz8y_virtuemart_orders.created_on <= '2014-07-20 00:00:00';**
UPDATE pvz8y_shopping_list
INNER JOIN pvz8y_virtuemart_product_categories ON pvz8y_shopping_list.virtuemart_product_id = pvz8y_virtuemart_product_categories.virtuemart_product_id
SET pvz8y_shopping_list.virtuemart_category_id = pvz8y_virtuemart_product_categories.virtuemart_category_id;
UPDATE pvz8y_shopping_list
INNER JOIN pvz8y_virtuemart_categories_en_gb ON pvz8y_shopping_list.virtuemart_category_id = pvz8y_virtuemart_categories_en_gb.virtuemart_category_id
SET pvz8y_shopping_list.category_name = pvz8y_virtuemart_categories_en_gb.category_name;
as you can see use the sql statements to create the shopping_list table and currently only show the results but I would like to be able to not have to create the table in the backend each time the date (highlighted in bold changes).
TRUNCATE.CREATE TEMPORARY TABLE.