Page 1 of 1

mysql_fetch_row with session

Posted: Tue May 18, 2010 3:17 pm
by spacebiscuit
Hi,

I'm trying to write the row of an mysql quesry result into a session array:

Code: Select all

$_SESSION[data]=mysql_fetch_row($result);
I'm then trying to write the data as follows:

Code: Select all

echo"$_SESSION[data][del]";
However that gives me:

Code: Select all

Array
What am I doing wrong?

Thanks in advance,

Rob.

Re: mysql_fetch_row with session

Posted: Tue May 18, 2010 3:31 pm
by flying_circus
Use one of the following to see what your array looks like

Code: Select all

print_r($_SESSION['data']) 

Code: Select all

var_dump($_SESSION['data']) 

Re: mysql_fetch_row with session

Posted: Tue May 18, 2010 3:33 pm
by spacebiscuit
It seems I was missing the quotations:

this works:

Code: Select all

print_r($_SESSION['data'][0]);
How do I output the variable using echo though:

Code: Select all

echo"$_SESSION[del][1]";
If I include the quotations I get a string escape error!

Thanks for your help.

Rob.

Re: mysql_fetch_row with session

Posted: Tue May 18, 2010 4:44 pm
by flying_circus
What happens when you try the following?

Code: Select all

if($result)
  $_SESSION['data'] = mysql_fetch_row($result);

  echo $_SESSION['data'][0];