0

i want to make a crical repot that notifies the admin if the products in inventory is running out lol. need some help :)

<?php include ('config.php'); ?>
<?php 


$result=mysql_query("select * from inventory");
$num=mysql_num_rows($result);
$qtyleft=['qtyleft'];
$name=['name'];

if($qtyleft <= 5){
                        while ($row=mysql_fetch_array($result, MYSQL_ASSOC)){
                        echo '<span>'.$name.'</span>';
                        echo "almost out of stock";

}}

?>
3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by jayson.ako_1
2

You're if statement needs to be within the while loop. You can't assign the values to qtyleft and name until you have fetched the row, and you need the array name before the key value:

<?php
 include ('config.php'); 
?>

<?php

  $result=mysql_query("select * from inventory");
  $num=mysql_num_rows($result);


  while ($row=mysql_fetch_array($result, MYSQL_ASSOC))
  {

    $qtyleft=$row['qtyleft'];
    $name=$row['name'];

    if($qtyleft <= 5)
    {
      echo '<span>'.$name.'</span>';
      echo "almost out of stock";
    }

  }

?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.