Jump to content

Stock movements export


b1000

Recommended Posts

Hi! after many attempts and following examples here on the forum I have obtained this code who work fine on mysql manager on prestashop;

SELECT o.id_order AS "ID Ordine", od.product_id AS "ID Prodotto",od.product_attribute_id AS "ID Combinazione", od.product_name AS "Nome Prodotto", od.product_quantity AS Quantita, o.valid AS Finalizzato
FROM ps_order_detail od
INNER JOIN ps_orders o 
ON o.id_order = od.id_order
WHERE o.date_add > DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 365 DAY),'%Y-%m-%d')

Than, I have create a php file to place in the root of my prestashop installation to otain the result in browser, who work fine:

<!DOCTYPE html>
<html>
<body>

<?php
$servername = "localhost";
$username = "nbbdvvyhud";
$password = "uz8QYXeXfV";
$dbname = "nbbdvvyhud";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT o.id_order AS 'ID Ordine', od.product_id AS 'ID Prodotto',od.product_attribute_id AS 'ID Combinazione', od.product_name AS 'Nome Prodotto', od.product_quantity AS Quantita, o.valid AS Finalizzato
FROM ps_order_detail od
INNER JOIN ps_orders o 
ON o.id_order = od.id_order
WHERE o.date_add > DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 365 DAY),'%Y-%m-%d')";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "ID Ordine: " . $row["ID Ordine"]. " - ID Prodotto: " . $row["ID Prodotto"]. " - ID Combinazione: " . $row["ID Combinazione"]. " - Nome Prodotto: " . $row["Nome Prodotto"]. " - Quantita: " . $row["Quantita"]. " - Finalizzato: " . $row["Finalizzato"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

</body>
</html>

Now, I have the necessity to create a php file to EXPORT IN CSV the data.. I have tryed in some way but with no result :((

Someone can help me?

THANK'U VERY VERY MUCH!

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...