mysql_fetch_row with session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

mysql_fetch_row with session

Post 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.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: mysql_fetch_row with session

Post 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']) 
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: mysql_fetch_row with session

Post 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.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: mysql_fetch_row with session

Post 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];
Post Reply