I search some query to Count the value of same row in my database I have product_description
in my table
called delevery
where you can see list of all product and quantity
where can see list the quantity of the product.
I found this code but I don't know how to echo this my my webpage?
SELECT quantity, count(*) as 'count quantity'
FROM delivery
GROUP BY product_description
Try this. It will return JSON to your application
<?php
$DB_NAME = 'DATABASE_NAME';
$DB_HOST = 'DATABASE_HOST';
$DB_USER = 'DATABASE_USER';
$DB_PASS = 'DATABASE_PASSWORD';
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$yourValue = $request->yourValue;
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
$sql="SELECT quantity, count(*) as 'quantity' FROM delivery GROUP BY product_description";
$result = $mysqli->query($sql) or die($mysqli->error.__LINE__);
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
$result1 = array();
while($row = mysql_fetch_array($result)){
array_push($result1, $row);
}
echo json_encode($result1);
?>
try to show your result with function var_dump();
$query="SELECT quantity, count(*) as 'quantity' FROM delivery GROUP BY product_description";
$result = mysql_query($query);
var_dump($result);