Re: RE: [newbie] drop down boxes
| From: | Philip Olson | Date: | Tue, 08 Apr 2003 00:01:15 +0000 |
| Subject: | Re: RE: [newbie] drop down boxes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-142770@lists.php.net to get a copy of this message | ||
> > > if(!isset($severity))
> > > {
> > > $_SESSION['querystring'] = "SELECT bugid, status, severity,
> > > assigned_to,
> > > summary, date_opened
> > > , estimated_completion, related_file, created_by
> > > FROM Bug";
> > > }
> > > else
> > > {
> > > $_SESSION['querystring'] = "SELECT bugid, status, severity,
> > > assigned_to,
> > > summary, date_opened, estimated_completion, related_file, created_by
> >FROM
> > > Bug WHERE severity ='$severity' LIMIT 40";
> > > }
> > > ?>
> > >
> > > //then in file2.php
> > > session_start();
> > > $db_result = mysql_query($_SESSION['querystring']) or
> >die(mysql_error());
> >
> >Storing a SQL statement as a session variable seems
> >like a bad idea, you really should rewrite your code
> >to not do this.
>
> I use $_SESSION to pass variables across scripts. I originally tried
> session_register('variable') but it did not ever seem to to work across
> scripts.(Even though register_globals was set to on)
>
> Not sure how to pass variables across scripts other than using session
> variables. what problems may i hit in the future if I use $_SESSION
You can pass variables but you don't have to pass an entire
sql query. Also, consider $_REQUEST as it's GET, POST,
and/or COOKIE. A simple example:
http://www.example.com/showme.php?sort=date_opened
$sorts = array('severity', 'assigned_to', 'date_opened');
if (@in_array($_REQUEST['sort'], $sorts)) {
$sort = $_REQUEST['sort'];
} else {
$sort = 'severity';
}
$sql = "SELECT stuff FROM it ORDER BY $sort LIMIT 0,40";
Or if you really want to, you can pass 'sorted' or whatever
through $_SESSION although if you don't need a session,
consider not using one.
Regards,
Philip