Re: Store array as Session Variable

From: Date: Mon, 28 Jul 2003 20:09:32 +0000
Subject: Re: Store array as Session Variable
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-157234@lists.php.net to get a copy of this message
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/


« previous php.general (#157234) next »