Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Array problem

  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Array problem

    PHP Code:
    $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?

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    you're writing over the values on each loop:
    PHP Code:
    $itemid $g['itemid']; 
    $itemid[$count] = $itemid
    change to:
    PHP Code:
    $itemid[$count] = $g['itemid']; 
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •