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";

}}

?>

Recommended Answers

All 2 Replies

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";
    }

  }

?>

thankyou so much! bro, it works now i really appreciate your help tahnks again :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.