Re: WHERE field = a range of values (value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 24 May 2011 23:47:47 +0700, "Paul S" <paul.s@xxxxxxxxxxxxxx> wrote:

On Tue, 24 May 2011 21:09:34 +0700, "Richard S. Crawford" <rscrawford@xxxxxxxxxxxx> wrote:

On Tue, May 24, 2011 at 6:51 AM, Paul S <paul.s@xxxxxxxxxxxxxx> wrote:

I'd like to check a table to retrieve rows for which one field equals one
of a set of values

....
#get products(fields) in category list
   while ($row = $db_connect->fetch_array($productsincategory_list)) {
      $product = $row ['selection'];
      $fields = "$fields" . " $product,";
   }
   $fields = substr($fields,'',-1);

###### echo "$fields<br><br>";
###### $fields = Prod1, ProD2, Prod3

This ...

$db_connect->fetch_array($sql_result);

$store_result = $db_connect->query("select * from $sql_usertable WHERE
(($sql_usertable.product1 = '($fields)')||( $sql_usertable.product2 =
'($fields)')||($sql_usertable.product3 = '($fields)')) order by id desc
limit $entry, $entries_per_page");

doesn't work. It selects nothing (obviously because no single field equals
' (Prod1, Prod2, Prod3) '). But it's the idea. Can I change the:

= '($fields)'

syntax I'm trying?

The actual select checks more fields for this or that and gets more
complicated so I'd like to keep this as simple
as possible. I would like to do this without UNIONS (in one pass) if
possible (my
dbsql.php doesn't seem to go beyond regular query).


Try "in":

where productx in (Prod1, Prod2, Prod3)




THANKS. You saved me another day of frustration trying UNION! :-)

In addition your answer also got me here:
http://dev.mysql.com/doc/refman/4.1/en/comparison-operators.html


Except when $fields = '' (blank) >>> MySql error. Can put in if but leaves an undefined resource (warning). Any way to initialize a resourse? ($store_result = $db_connect->query)?
--
Using Opera's revolutionary email client: http://www.opera.com/mail/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux