...

View Full Version : Array problem



ole90
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());
$n=mysql_num_rows($sel);
if($n == 0) {
$input = "You do not own this item.";
error($input);
}
$g=mysql_fetch_array($sel);
$itemid = $g['itemid'];
$itemid[$count] = $itemid;
$count++;

}

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?

GJay
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'];



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum