Re: SELECT query with multiple "WHERE" Clause

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

 




$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 <nasreen_laghari@xxxxxxxxx>
To: php-db@xxxxxxxxxxxxx
Date: Wed, 27 Feb 2008 15:44:23 -0800 (PST)
Subject:  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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux