Bluehost.com Web Hosting $6.95

Re: [PHP] Store array as Session Variable

This is a discussion on Re: [PHP] Store array as Session Variable within the PHP General forums, part of the PHP Programming Forums category; --- Pushpinder Singh Garcha <pgarcha@adelphia.net> wrote: > I am trying to store the value in row['company'] ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-28-2003
Chris Shiflett
 
Posts: n/a
Default Re: [PHP] Store array as Session Variable

--- Pushpinder Singh Garcha <pgarcha@adelphia.net> wrote:
> I am trying to store the value in row['company'] in an array
> called $company_name.


I see now. I think you might find this a bit simpler (if I understand
correctly):

$company_name = array();
while ($row = mysql_fetch_assoc($result))
{
$company_name[] = $row['company'];
}

Also, at this point, you should probably examine the contents of $company_name
before bothering with the session stuff. You may be having trouble with your
query or something that is totally unrelated to sessions. Try John's suggestion
of print_r() by doing something like this:

echo '<pre>';
print_r($company_name);
echo '</pre>';

Hope that helps.

Chris

=====
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/
Reply With Quote
  #2 (permalink)  
Old 07-28-2003
Pushpinder Singh Garcha
 
Posts: n/a
Default Re: [PHP] Store array as Session Variable

Thanks Chris,

I am able to see the contents of the $company_name array. The next
part involves storing this as a session variable.

I am trying to link this page to another search page using the <a
href=\"full-profile.php?name=".$row['company']. "\">--Link--</a>

> while ($row = mysql_fetch_assoc($result))
> {
> "<TR BGCOLOR=$bgcolor>
> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
> face=\"Verdana, Arial, Helvetica,
> sans-serif\">$row[company]</font></TD>
> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
> face=\"Verdana, Arial, Helvetica, > sans-serif\">$row[name_1]</font></TD>
> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
> face=\"Verdana, Arial, Helvetica,
> sans-serif\">$row[phone_1]</font></TD>
> <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana,
> Arial, Helvetica, sans-serif\">$row[city]</font></TD>
> <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana,
> Arial, Helvetica, sans-serif\">$row[url]</font></TD>
> <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana,
> Arial, Helvetica, sans-serif\">$row[email_1]</font></TD>
> <TD align=\"center\"><font color=\"#333333\" size=\"1\"
> face=\"Verdana, Arial, Helvetica, sans-serif\"><a
> href=\"full-profile.php?name=".$row['company']."\">--Link--</a></
> font></TD> </TR>";


> $company_name[] = $row['company'];


// try to register the variable
$_SESSION['link'] = $company_name;
> }



What would be the best way to register the array $company_name as a
session var and access it on the following page. $_SESSION['link'] =
$company_name;
does not seem to work since it gives NULL when i try to echo
$_SESSION['link'];


Thanks in advance
--Pushpinder



On Monday, July 28, 2003, at 03:43 PM, Chris Shiflett wrote:

> --- Pushpinder Singh Garcha <pgarcha@adelphia.net> wrote:
>> I am trying to store the value in row['company'] in an array
>> called $company_name.

>
> I see now. I think you might find this a bit simpler (if I understand
> correctly):
>
> $company_name = array();
> while ($row = mysql_fetch_assoc($result))
> {
> $company_name[] = $row['company'];
> }
>
> Also, at this point, you should probably examine the contents of
> $company_name
> before bothering with the session stuff. You may be having trouble
> with your
> query or something that is totally unrelated to sessions. Try John's
> suggestion
> of print_r() by doing something like this:
>
> echo '<pre>';
> print_r($company_name);
> echo '</pre>';
>
> Hope that helps.
>
> Chris
>
> =====
> Become a better Web developer with the HTTP Developer's Handbook
> http://httphandbook.org/
>


Reply With Quote
  #3 (permalink)  
Old 07-28-2003
Chris Shiflett
 
Posts: n/a
Default Re: [PHP] Store array as Session Variable

--- Pushpinder Singh Garcha <pgarcha@adelphia.net> wrote:
> I am able to see the contents of the $company_name array. The
> next part involves storing this as a session variable.


Assuming $company_name is set correctly, as you verified, this should suffice:

$_SESSION['company_name'] = $company_name;

I should mention that you will need a session_start() call on the page you wish
to set session variables on as well as any page that you wish to read session
variables from.

> I am trying to link this page to another search page using the <a
> href=\"full-profile.php?name=".$row['company']. "\">--Link--</a>
>
> > while ($row = mysql_fetch_assoc($result))
> > {
> > "<TR BGCOLOR=$bgcolor>
> > <TD align=\"left\"><font color=\"#666666\" size=\"1\"
> > face=\"Verdana, Arial, Helvetica,
> > sans-serif\">$row[company]</font></TD>
> > <TD align=\"left\"><font color=\"#666666\" size=\"1\"
> > face=\"Verdana, Arial, Helvetica, > sans-serif\">$row[name_1]</font></TD>
> > <TD align=\"left\"><font color=\"#666666\" size=\"1\"
> > face=\"Verdana, Arial, Helvetica,
> > sans-serif\">$row[phone_1]</font></TD>
> > <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana,
> > Arial, Helvetica, sans-serif\">$row[city]</font></TD>
> > <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana,
> > Arial, Helvetica, sans-serif\">$row[url]</font></TD>
> > <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana,
> > Arial, Helvetica, sans-serif\">$row[email_1]</font></TD>
> > <TD align=\"center\"><font color=\"#333333\" size=\"1\"
> > face=\"Verdana, Arial, Helvetica, sans-serif\"><a
> > href=\"full-profile.php?name=".$row['company']."\">--Link--</a></
> > font></TD> </TR>";


This is about the best example I've seen as to why stylesheets are handy. :-)

Is there an echo in there that I missed? I don't see how this is being output.

Chris

=====
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:58 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0