Re: mySQL Queries using PHP's SESSION variables

From: Date: Thu, 25 Jul 2002 19:59:15 +0000
Subject: Re: mySQL Queries using PHP's SESSION variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-109595@lists.php.net to get a copy of this message
On Thu, Jul 25, 2002 at 02:51:13PM -0400, Anup wrote: > Hello, I am stuck here. In the name of efficiency I want to lower the number > of callls to the database. So I am trying to give the most stringent query > possible. This is the problem: I have stored the surfers shopping cart, > where each item is stored as a session variable.Now on the database I have > ALL inventory items, but I want to only display the details of what the user > has in his cart. > eg. : I want something like this: > > $result = mysql_query("SELECT * from Inventory where ItemNumber is in > $HTTP_SESSION_VARS"); Other folks have made suggestions, but this is way simpler. Assuming the session vars and ItemNumber are numbers: $result = mysql_query('SELECT * from Inventory where ItemNumber IN (' . implode(',', $_SESSION) . ')'); If it's strings: $result = mysql_query("SELECT * from Inventory where ItemNumber IN ('" . implode("','", $_SESSION) . "')"); --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

« previous php.general (#109595) next »