mysql - Having trouble displaying results from a database using php -


i've annotated code problem, suggestions on solving this? been stuck on couple of hours now..

<?php include("header.php"); $inv = mysql_query("select `item_id` `user_items` `user_id`='".$_session['uid']."'") or die(mysql_error()); $linv = mysql_fetch_array($inv);  //need display item_id's user_items table user_id field = $_session['uid'] (or 1 testing purposes.) //for reason, every foreach , while loop method have tried giing me false data (1,1).  right data should be: 1, 4. //the database table contains 3 columns: slot_id, user_id, item_id. //those columns contain following data: 1       1          1 //                                          2       2          4 //                                          3       1          4 //surely should return $linv array containing values 1 , 4?  what's going on?   } include("footer.php"); ?> 

change

$linv = mysql_fetch_array($inv);   while(list($key, $value) = each($linv))  {       echo($value);   }

to

while($linv = mysql_fetch_array($inv))  {      echo $linv['item_id'] . ' ';  }

edit: problem reason
- first problem $linv = mysql_fetch_array returns next row , stores array in $linv, in beginning starts row # 0
first problem missing loop retrieve rows

- may ask self "if i'm getting 1 row why output 1 1", because mysql_fetch_array accepts second parameter detriments fetch mode (mysql_assoc associative array can accessed columns names in query, mysql_numeric numeric array can accessed numbers 0,1,2 ... in same order columns specified in select clause), when don't pass parameter, mysql_both used default , first row ["0" => "1" , "item_id" => "1"]
doing looping through elements in first row


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -