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'] ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
--- 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/ |
|
|||
|
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/ > |
|
|||
|
--- 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/ |