multidimensional array insert problem

Discussion in 'PHP' started by dmanto2two, Mar 29, 2010.

  1. #1
    I'm trying to put a multidimensional array into a cookie.
    but everytime i do it the page crashes. does anyone know more about multidimensional things?
    session_start();
    require_once('function.php');
    $online_list = $_SESSION['online_list'];
    $friend = $_GET['user_id'];

    $online_list = array();
    $stack = array(
    "$friend" => array(
    "display" => "0"
    )
    );
    array_push($statck, $online_list);
    $_SESSION['online_list'] = $online_list;
    unset($_SESSION['online_list']);

    i also tried
    $online_list = $_SESSION['online_list'];
    $friend = $_GET['user_id'];
    if(!empty($online_list)){
    $online_list = array();
    $online_list["0"]["user_id"] = $friend;
    $online_list[$num]["online"] = 0;
    $_SESSION['online_list'] = $online_list;
    }
    else{
    $num = count($online_list);
    $online_list[$num]["user_id"] = $friend;
    $online_list[$num]["online"] = 0;
    $_SESSION['online_list'] = $online_list;
    thanks to all. I'm stumped
     
    dmanto2two, Mar 29, 2010 IP
  2. Narrator

    Narrator Active Member

    Messages:
    392
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    80
    #2
    Not sure is this is a typo, should be $stack, right?
    
    array_push($statck, $online_list);
    
    PHP:
    also on the second part, you didn't assign a variable for $num in the IF before the ELSE
    
    $online_list[$num]["online"] = 0;
    
    PHP:
     
    Narrator, Mar 29, 2010 IP
  3. dmanto2two

    dmanto2two Peon

    Messages:
    56
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks man i amended the stack variable but it still crashed.
    the online num line i just forgot, but its supposed to be
    session_start();
    require_once('bookmark_fns.php');
    $online_list = $_SESSION['online_list'];
    $friend = $_GET['user_id'];
    if(!empty($online_list)){
    $online_list = array();
    $online_list["0"]["user_id"] = $friend;
    $online_list[$num]["online"] = 0;
    $_SESSION['online_list'] = $online_list;
    }
    else{
    $num = count($online_list);
    $online_list[$num]["user_id"] = $friend;
    $online_list[$num]["online"] = 0;
    $_SESSION['online_list'] = $online_list;
    }
    anyway i was guessing this must just be a really inefficent method. this php is code is repeated once every 100 miliseconds. so i cranked it up to 1000 then 100000. still crashes. What i'm trying to do is assosiate a user id with with a boolean. i was thinking aboutstoring the bool in the same array cell as the id and then doing a string separation since the user ids are always 13 char long and this multi dimensional array buissnes isnt working.Anyone know if that would be more efficent or better way? Thanks for the response narrator.
     
    dmanto2two, Mar 29, 2010 IP
  4. K.Meier

    K.Meier Well-Known Member

    Messages:
    281
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #4
    What do you mean by crash? Do you get a PHP error, does the site time out, or does your actually browser crash/freeze/stop responding?
     
    K.Meier, Mar 29, 2010 IP
  5. Narrator

    Narrator Active Member

    Messages:
    392
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    80
    #5
    You were still missing the $num, try this
    
    session_start();
    require_once('bookmark_fns.php');
    $online_list = $_SESSION['online_list'];
    $friend = $_GET['user_id'];
    if(!empty($online_list)){
    $num = count($online_list); //you were missing this not sure if it was the prob
    $online_list = array();
    $online_list[0]["user_id"] = $friend;  //dont need to quote the 0 but I doubt that was the prob
    $online_list[$num]["online"] = 0;
    $_SESSION['online_list'] = $online_list;
    }
    else{
    $num = count($online_list);
    $online_list[$num]["user_id"] = $friend;
    $online_list[$num]["online"] = 0;
    $_SESSION['online_list'] = $online_list;
    }
    
    PHP:
     
    Narrator, Mar 30, 2010 IP
  6. dmanto2two

    dmanto2two Peon

    Messages:
    56
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Sorry i managed not to define $num again. Anyway when the page crashes the current tab stops responding to all clicks, then after 30 or so seconds the page goes white. if u reload the page though the cookie has the right info. I'll try putting all the info in 1 one string. But if anyone knows about multidimensional array bracket syntax i would be super grateful. thanks for all the responses guys
     
    dmanto2two, Mar 30, 2010 IP
  7. dmanto2two

    dmanto2two Peon

    Messages:
    56
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Wow my bad. I read over my own description of the array. And realized that this was a javascript problem. found and fixed the error. Anyway thanks to all for respondin even if i am a moron
     
    dmanto2two, Mar 30, 2010 IP