View Full Version : Array problem

08-21-2007, 12:57 AM
$count = 1;
foreach($trade as $val) {
$val = checkinput($val);
$sel=mysql_query("SELECT * FROM `inventory` WHERE `ID` = '$val' AND `userid` = '$userid2'") or die(mysql_error());
if($n == 0) {
$input = "You do not own this item.";
$itemid = $g['itemid'];
$itemid[$count] = $itemid;


Basically, my script is trying to put the itemid of an item into an array. The problem i'm getting is that, it's not saving the values in the array. For example, if i have 3 items and it puts them into the array, it will only save the 3rd item in the array $itemid[3] and 1 and 2 will be blank.

Any ideas =X?

08-21-2007, 08:30 AM
you're writing over the values on each loop:

$itemid = $g['itemid'];
$itemid[$count] = $itemid;

change to:

$itemid[$count] = $g['itemid'];