Adamant Arrays!

Discussion in 'PHP' started by prabha_friend, Jun 29, 2009.

  1. #1
    index.php
    function User_Role_Menu($Role_id)
    {
    $myrset = mysql_query("CALL SP_User_Role_Menu(".$Role_id.")");
    //fetch and read and session the tabs and links for this user
    //A General Counter
    $counter = '0';
    while($User_Role_Menu_Set_Row = mysql_fetch_array($myrset))
    {
    //echo $User_Role_Menu_Set_Row['TAB_LINK']; - Guruji
    $_SESSION['Tabs'][$counter]=$User_Role_Menu_Set_Row['TAB_NAME'];
    $_SESSION['Links'][$counter]=$User_Role_Menu_Set_Row['TAB_LINK'];
    echo $counter;
    $counter = $counter+1;
    }
    }
    something.php
    <?php
    $MYOBJ->User_Role_Menu($_SESSION['ROLE_ID']);
    ?>
    why this generates this error „Warning: Cannot use a scalar value as an array“? Where's the problem whats the remedy.
    Dear Friends. Please dont suggest to do in any other way. I am very curious about the errors I am getting while i work even though I achieved it by some other way. I still wants to understand. Thanks in advance.
     
    prabha_friend, Jun 29, 2009 IP
  2. prabha_friend

    prabha_friend Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    index.php
    function User_Role_Menu($Role_id)
    {
    //getting the records for that particular role
    //echo $Role_id; - Test Passed
    $myrset = mysql_query("CALL SP_User_Role_Menu(".$Role_id.")");
    //Return a recordset of tabs and menus. So we have to fetch
    //A General Counter
    $counter = 0;
    //updating the session with tabs and menuslinks arrays
    while($User_Role_Menu_Set_Row = mysql_fetch_array($myrset))
    {
    //echo $User_Role_Menu_Set_Row['TAB_NAME']; - Test Passed
    //Even no for Tabname and odd for tablink
    $_SESSION[$counter]=$User_Role_Menu_Set_Row['TAB_NAME'];
    //echo $_SESSION[$counter]; - Test Passed
    $_SESSION[$counter+1]=$User_Role_Menu_Set_Row['TAB_LINK'];
    //echo $_SESSION[$counter+1]; - Test Passed
    $counter = $counter+1;
    }
    }
    something.php
    <?php
    if(!isset($_SESSION))
    {
    session_start();
    }
    $counter = 0;
    while($counter <= count($_SESSION))
    {
    echo $_SESSION[$counter];
    echo $_SESSION[$counter+1];
    $counter = $counter+1;
    }
    ?>
    Result:
    Notice: Undefined offset: 0
    Notice: Undefined offset: 1
    Notice: Undefined offset: 3
    .......................................... n.
    Why? Whats the Problem? We can't store arrays in Session?
    Suggest me a way to achieve this. Work at stake. Kindly help.
     
    prabha_friend, Jun 29, 2009 IP
  3. Goramba

    Goramba Peon

    Messages:
    128
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    index.php
    function User_Role_Menu($Role_id)
    {
    $myrset = mysql_query("CALL SP_User_Role_Menu(".$Role_id.")");
    while($row = mysql_fetch_array($myrset))
    {
    $counterarray[]=$row['TAB_NAME'];
    $counterplusarray[]=$row['TAB_LINK'];
    }
    $counter= implode(",", $counterarray);
    $counterplus= implode(",", $counterplusarray);
    // Now you can use that in the page. And to make it a session var:

    $_SESSION['counter']="$counter";
    $_SESSION['counterplus']="$counterplus";
    // Not tested with the quotes there, play with that.


    }



    something.php
    <?php
    // It won't overwrite a session so you don't need to check.
    session_start();

    $counter=$_SESSION['counter'];
    $counterplus=$_SESSION['counterplus'];

    $counters = explode(",", $counter);
    $counterpluss = explode(",", $counterplus);

    foreach($counters as $counter)
    {
    echo $counter;
    }
    foreach($counterpluss as $counterplus)
    {
    echo $counterplus;
    }

    ?>
     
    Goramba, Jun 29, 2009 IP