-5

I need to know what to do with $rows=array(). why it is used and how i could use it further. would like to get some suggestions and answers

  <?php


    $dbhost = "localhost"; 
    $dbuser = "root";
    $dbpass = "";
    $dbdb = "yumyum";


    $connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("connection error");


    mysql_select_db($dbdb) or die("database selection error");


    $id = $_POST['id'];


    $query1=mysql_query("SELECT Quantity,id FROM `yumyum`.`food` where  `food`.`id` LIKE $id");
    $rows = array();

    while($r = mysql_fetch_assoc($query1)) {

        $output = $r['Quantity'];


            echo $output;
            $query2=mysql_query("UPDATE food SET Quantity = Quantity - 1 where  `food`.`id` LIKE ".$r["id"]);
    }

    ?>
Mike Baranczak
  • 8,291
  • 8
  • 47
  • 71

1 Answers1

6

In your script it does nothing but initialize the variable $row with an array type. It would probably be intended to be used in your while loop ($r):

...
$query1=mysql_query("SELECT Quantity,id FROM `yumyum`.`food` where  `food`.`id` LIKE $id");
$r = array();

while($r = mysql_fetch_assoc($query1)) {
...

See PHP basics:

It is not necessary to initialize variables in PHP however it is a very good practice.

You should also stop using mysql_ functions. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which.

Kermit
  • 33,827
  • 13
  • 85
  • 121