hola grupo del foro.
espero puedan ayudar a resolver este inconveniente. tengo el siguiente código que debe mostrarme la cantidad del mes:
- la cantidad de ventas
- el total de dinero
- el total de ganancia
este es el error que me aparece.
Notice: Trying to get property 'num_rows' of non-object in http://localhost/001/monthly.php on line 115
espero se pueda resolver, desde ya mil gracias por leerme.
monthly.php
Código PHP:
Ver original<?php
$servername = "localhost";
$username = "username";
$password = "password";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully";
$sql = "SELECT v.gty_s,v.vClient DATE_FORMAT(v.sFecha, '%Y-%m-%e') AS sFecha,p.nameProducts,p.barCode
SUM(v.total_s) AS total_s_price
SUM(v.gty_s) AS total_qty
SUM(v.moneymaking) AS total_moneymaking
FROM sales v LEFT JOIN products p ON v.product_id = p.product_id WHERE DATE_FORMAT(v.sFecha, '%Y' ) = '{$year}'
GROUP BY DATE_FORMAT(v.sFecha, '%c' ),v.product_id
ORDER BY DATE_FORMAT(v.sFecha, '%c' ) ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) { // Error on line 115
while($row = $result->fetch_assoc()) {
?>
- Mostrar por mes:<br>
Cantidad: <?php echo $total_qty = $row["total_qty"]; ?> <br>
Total: <?php echo $total_s_price = $row["total_s_price"]; ?> <br>
Ganancia: <?php echo $total_moneymaking = $row["total_moneymaking"]; ?> <br>
<?php
}
} else {
echo "0 result";
}
$conn->close();
?>
Tabla
Código HTML:
Ver originalCREATE TABLE `sales` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`product_id` int(11) unsigned NOT NULL,
`gty_s` int(11) NOT NULL,
`total_s` decimal(25,2) DEFAULT 0.00,
`moneymaking` decimal(25,2) DEFAULT 0.00,
`vClient` varchar(255) DEFAULT NULL,
`sFecha` datetime NOT NULL,
CREATE TABLE `products` (
`product_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`nameProducts` varchar(255) NOT NULL,
`barCode` varchar(60) NOT NULL,
`pFecha` datetime NOT NULL,