Jump to content

Datasets Don't Do that! Why?


prabha_friend

Recommended Posts

index.php

<?php

$_SESSION['Set'] = mysql_query("Select * from SOMETABLE");

$_SESSION['Test']=“Testval“;

redirect('Dummy.php');

?>

Dummy.php

<?php

echo $_SESSION['Test'];

$myrow = mysql_fetch_array($_SESSION['Set']);

echo $myrow['USERID'];

?>

Why Dont I get the results from a Session's Dataset variable like any other Session's variables. How to pass datasets from page to page. Work on stake. Help needed. Thanks in advance.

Link to comment
Share on other sites

Firstly, you have no call to session_start() so your session aren't initialised. You also have a parse error on the...

 

$_SESSION['Test']=“Testval“;

 

line. Use "double" quotes, not whatever it is you are using.

 

thirdly, you cannot pass around a database resource through sessions. They are unable to be serialised.

Link to comment
Share on other sites

You can not serialize result sets, or any other resource types.  You can however, fetch all the data, store it in an array and serialize it.  Session variables are serialized by php, which is how they persist between requests.

Link to comment
Share on other sites

Thank you everybody for answering me at the very earliest. I am very new to php. Your guidance are very useful to me. I hope you take me wrong. If I ask another question here.

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.