I have a simple query to select some information from the database:
$dep_qry = "select product_name, sum(theoretical_stock_level) as opening_stock, sum(quantity_scanned) as closing_stock, department_description, stock_item_code, custom_1 AS size, IFNULL(unit_cost_price, 0.00) AS cost_price from stocktake_products where stocktake_id = '{$stocktake_id}' AND is_deli = 0
group by product_name, department_description
order by department_description ASC;";
$dep_res = db::c()->query($dep_qry);
I then have the following code to put products with a cost price of 0.00 into an array. I then check the number of elements in the array. If the array has some information in it, I want to display an alert for the user to tell him which items have a cost price of 0. The following code works, but I am wondering if its possible to display each entry from the array on a separate line in the alert box? Just to make it more user friendly.
while ($row1 = $dep_res->fetch(PDO::FETCH_ASSOC))
{
$cost_price = number_format($row1['cost_price'],2);
$pname = $row1['product_name'];
if ($cost_price == 0.00)
{
$products[$i] = $pname;
}
$i++;
}
$numOfNoCosts = count($products);
if ($numOfNoCosts > 0)
{
echo "<script> alert('".json_encode($products)."') </script>";
}
If there is a better way of doing this, I am more than happy to take on suggestions!