[PHP-DB] SELECT query with multiple WHERE Clause

2008-02-27 Thread Nasreen Laghari
Hi All,

Thank you for increasing my knowledge about PHP/MYSQL.

I am creating a SEARCH, by only using one table. The search form  is same as 
Inserting item (search has form of all fields in table ), difference is SEARCH 
page doesnt have validation . Therefore user can enter information in any of 
field. I would like to know how to write a SELECT query which has multiple 
where clause with OR operator.

shall we write:

$query = mysql_query(SELECT * from gig WHERE Name='$name' || WHERE 
gig_fdate='$sdate');

OR

$query = mysql_query(SELECT * from gig WHERE gigName='$gig_name' OR WHERE 
gig_fdate='$sdate');

OR

$query = mysql_query(SELECT * from gig WHERE gigName='$gig_name' ||  
gig_fdate='$sdate');


Regards

Nasreen


  

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping

Re: [PHP-DB] SELECT query with multiple WHERE Clause

2008-02-27 Thread Chris



$query = mysql_query(SELECT * from gig WHERE gigName='$gig_name' OR WHERE 
gig_fdate='$sdate');


This one.

I'd suggest you get a book to help you with the basics, something like 
this should do (first hit in amazon, haven't actually read this 
particular book):


http://www.amazon.com/Learning-MySQL-Seyed-Saied-Tahaghoghi/dp/0596008643/

There's lots of stuff to learn in sql.

--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP-DB] SELECT query with multiple WHERE Clause

2008-02-27 Thread Greg Bowser
In MySQL, both OR and || are valid logical or operators.  You can only
have one Where clause, thus your last example is correct.

--GREG

On Wed, Feb 27, 2008 at 6:44 PM, Nasreen Laghari [EMAIL PROTECTED]
wrote:

 Hi All,

 Thank you for increasing my knowledge about PHP/MYSQL.

 I am creating a SEARCH, by only using one table. The search form  is same
 as Inserting item (search has form of all fields in table ), difference is
 SEARCH page doesnt have validation . Therefore user can enter information in
 any of field. I would like to know how to write a SELECT query which has
 multiple where clause with OR operator.

 shall we write:

 $query = mysql_query(SELECT * from gig WHERE Name='$name' || WHERE
 gig_fdate='$sdate');

 OR

 $query = mysql_query(SELECT * from gig WHERE gigName='$gig_name' OR WHERE
 gig_fdate='$sdate');

 OR

 $query = mysql_query(SELECT * from gig WHERE gigName='$gig_name' ||
  gig_fdate='$sdate');


 Regards

 Nasreen



  
 
 Looking for last minute shopping deals?
 Find them fast with Yahoo! Search.
 http://tools.search.yahoo.com/newsearch/category.php?category=shopping



Re: [PHP-DB] SELECT query with multiple WHERE Clause

2008-02-27 Thread Chris

Greg Bowser wrote:

In MySQL, both OR and || are valid logical or operators.  You can only
have one Where clause, thus your last example is correct.


Though in postgresql and db2 (and some other dbs) || means 
concatenate so stick with using the word OR in this situation 
otherwise you'll run into portability issues if you ever needed to move 
to another db.


--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP-DB] SELECT query with multiple WHERE Clause

2008-02-27 Thread Daniel Brown
On Wed, Feb 27, 2008 at 6:44 PM, Nasreen Laghari
[EMAIL PROTECTED] wrote:
  I am creating a SEARCH, by only using one table. The search form  is same as 
 Inserting item (search has form of all fields in table ), difference is 
 SEARCH page doesnt have validation . Therefore user can enter information in 
 any of field. I would like to know how to write a SELECT query which has 
 multiple where clause with OR operator.

SELECT * FROM tableName WHERE (colA LIKE '%value%' OR colB='1');

--- more ---

SELECT fieldA,fieldR,fieldT,fieldX FROM tableName WHERE
(colA='value' OR colB LIKE 'Hello%') AND colC='Active';

-- 
/Dan

Daniel P. Brown
Senior Unix Geek
? while(1) { $me = $mind--; sleep(86400); } ?

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



Re: [PHP-DB] SELECT query with multiple WHERE Clause

2008-02-27 Thread Stut

On 27 Feb 2008, at 23:44, Nasreen Laghari wrote:

Thank you for increasing my knowledge about PHP/MYSQL.


The question you ask below is basic SQL syntax. Please read the MySQL  
manual before asking here - answers at this level are all in there.


http://mysql.com/doc

Oh, and once you have it working try entering

';delete * from gig;select * from gig where Name='

(including quotes) into the gig_name form field. When you get over the  
loss of all your data go read about sanitising your input: http://php.net/mysql_real_escape_string


-Stut

--
http://stut.net/



I am creating a SEARCH, by only using one table. The search form  is  
same as Inserting item (search has form of all fields in table ),  
difference is SEARCH page doesnt have validation . Therefore user  
can enter information in any of field. I would like to know how to  
write a SELECT query which has multiple where clause with OR operator.


shall we write:

$query = mysql_query(SELECT * from gig WHERE Name='$name' || WHERE  
gig_fdate='$sdate');


OR

$query = mysql_query(SELECT * from gig WHERE gigName='$gig_name' OR  
WHERE gig_fdate='$sdate');


OR

$query = mysql_query(SELECT * from gig WHERE gigName='$gig_name'  
||  gig_fdate='$sdate');



Regards

Nasreen


  


Looking for last minute shopping deals?
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping


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



Re: [PHP-DB] SELECT query with multiple WHERE Clause

2008-02-27 Thread Stephen Johnson
$query = mysql_query(SELECT * from gig WHERE gigName='$gig_name' or
gig_fdate='$sdate');

You can not use more then one WHERE in your sql statement... And SQL accepts
OR and AND..  


--
Stephen Johnson c | eh
The Lone Coder

http://www.thelonecoder.com
continuing the struggle against bad code

http://www.fortheloveofgeeks.com
I¹m a geek and I¹m OK!
--




 From: Nasreen Laghari [EMAIL PROTECTED]
 Date: Wed, 27 Feb 2008 15:44:23 -0800 (PST)
 To: php-db@lists.php.net
 Subject: [PHP-DB] SELECT query with multiple WHERE Clause
 
 
 
 $query = mysql_query(SELECT * from gig WHERE gigName='$gig_name' ||
 gig_fdate='$sdate');

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



Re: [PHP-DB] SELECT query with multiple WHERE Clause

2008-02-27 Thread TG


$query = mysql_query(SELECT * FROM gig WHERE gigName='$gig_name' OR 
gig_fdate='$sdate');

You only use the WHERE clause once then use parenthesis, AND and OR to create 
the logical conditions.

If you have access to the mysql server, maybe through phpMyAdmin or 
something, I'd highly recommend forming your SQL statements using that, 
then creating your PHP once you've perfected your SQL.

SQL statements can be very powerful and sometimes dangerous and it's much 
easier to debug the SQL when you work with it by itself and not have to 
worry about any PHP issues too.

Assuming your MySQL server is on another server, if you have a Windows 
machine you can use a program like WinSQL Lite or Navicat to connection to 
the MySQL server (if it allows remote connections).

phpMyAdmin is probably the easiest option though.

-TG

- Original Message -
From: Nasreen Laghari [EMAIL PROTECTED]
To: php-db@lists.php.net
Date: Wed, 27 Feb 2008 15:44:23 -0800 (PST)
Subject: [PHP-DB] SELECT query with multiple WHERE Clause

 Hi All,
 
 Thank you for increasing my knowledge about PHP/MYSQL.
 
 I am creating a SEARCH, by only using one table. The search form  is same 
as Inserting item (search has form of all fields in table ), difference is 
SEARCH page doesnt have validation . Therefore user can enter information 
in any of field. I would like to know how to write a SELECT query which has 
multiple where clause with OR operator.
 
 shall we write:
 
 $query = mysql_query(SELECT * from gig WHERE Name='$name' || WHERE 
gig_fdate='$sdate');
 
 OR
 
 $query = mysql_query(SELECT * from gig WHERE gigName='$gig_name' OR WHERE 
gig_fdate='$sdate');
 
 OR
 
 $query = mysql_query(SELECT * from gig WHERE gigName='$gig_name' ||  
gig_fdate='$sdate');
 
 
 Regards
 
 Nasreen

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