RE: [PHP] Queries and Arrays

From: Date: Fri, 08 Dec 2000 07:03:25 +0000
Subject: RE: [PHP] Queries and Arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31928@lists.php.net to get a copy of this message
Something like this might be better for you. See if it works: <? //create a list of your uids: '1','2','3','4' $list = "'" . implode("','",$SESSION) . "'"; $result = mysql_query("SELECT * FROM data WHERE user = '$user' AND uid IN ($list) ORDER BY y1 DESC, lastname"); ... Is uid a string or an integer? If it's an integer, you can use this: <? //create list of uids 1,2,3,4 $list = implode(",",$SESSION); $result = mysql_query("SELECT * FROM data WHERE user = '$user' AND uid IN ($list) ORDER BY y1 DESC, lastname"); ... ---John Holmes... -----Original Message----- From: RealGM Webmaster [mailto:webmaster@realgm.com] Sent: Wednesday, December 27, 2000 3:21 PM To: php-general Subject: [PHP] Queries and Arrays Hi, I have a little question. I have an array that contains 25 values, and I need to compare each value to another value within a query. Previously I had 25 different variables and compared each individually, but then with more and more users using our system my session management was not working correctly so I was forced to change. Now, with the new change, I am getting the following error message: Parse error: parse error, expecting T_STRING' or T_VARIABLE' or `T_NUM_STRING' My query looks like the following: $result = mysql_query("SELECT * FROM data WHERE user = '$user' AND (uid = '$SESSION["p101"]' OR uid = '$SESSION["p102"]' OR uid = '$SESSION["p103"]' OR uid = '$SESSION["p104"]' OR uid = '$SESSION["p105"]' OR uid = '$SESSION["p106"]' OR uid = '$SESSION["p107"]' OR uid = '$SESSION["p108"]' OR uid = '$SESSION["p109"]' OR uid = '$SESSION["p110"]' OR uid = '$SESSION["p111"]' OR uid = '$SESSION["p112"]' OR uid = '$SESSION["p113"]' OR uid = '$SESSION["p114"]' OR uid = '$SESSION["p115"]' OR uid = '$SESSION["p116"]' OR uid = '$SESSION["p117"]' OR uid = '$SESSION["p118"]' OR uid = '$SESSION["p119"]' OR uid = '$SESSION["p120"]' OR uid = '$SESSION["p121"]' OR uid = '$SESSION["p122"]' OR uid = '$SESSION["p123"]' OR uid = '$SESSION["p124"]' OR uid = '$SESSION["p125') ORDER BY y1 DESC, lastname"); It is very long and tedious, and the problem lies in the calls to the array values $SESSION. Does anyone know if you can use an array in this manner, or so I have to convert each array value into a stand alone variable then compare from here? Thanks, Michael.

« previous php.general (#31928) next »