Select statement issue with multiple where statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
FatC
Forum Newbie
Posts: 4
Joined: Tue Dec 29, 2009 10:21 am

Select statement issue with multiple where statement

Post by FatC »

New to this whole php thing....and this doesn't make sense. I'm having a problem with a multiple select statement. When i use and it doesn't seem to work. When i use or or just one where statement it works fine. Is it a problem with two where statements on the same field?

I'm wanting to produce a list of entries from a date ($start) to a date ($end). If i use the and it only produces one field of data. Where if i use or it produces multiple rows. Any ideas?

Thanks!



code:

$sql = "SELECT * FROM request WHERE $start <= date AND $end >= date"
or die( void);

$result = mysql_query($sql);
while ($r = mysql_fetch_array($result))
{


$fname=$r["first_name"];
$lname=$r["last_name"];
$addr1=$r["address1"];
$cit=$r["city"];
$st=$r["state"];
$zip=$r["zip"];

?>
<tr>
<th>
<h1>"<?php echo ("$fname") ?>","<?php echo("$lname") ?>","or current resident","<? echo("$addr1")?>","<? echo("$cit")?>","<? echo("$st")?>","<? echo("$zip")?>"</h1>


<?
}

?>
Last edited by FatC on Tue Dec 29, 2009 11:40 am, edited 1 time in total.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Select statement issue with multiple where statement

Post by Darhazer »

Try with:

Code: Select all

SELECT * FROM request WHERE `date` >= '$start' AND `date` <= '$end'
If does not work, please output the query itself (with the variable replaced by it's value), as well as the schema of the table
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Select statement issue with multiple where statement

Post by AbraCadaver »

--Or--

Code: Select all

$sql = "SELECT * FROM `request` WHERE `date` BETWEEN '$start' AND '$end'";
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
FatC
Forum Newbie
Posts: 4
Joined: Tue Dec 29, 2009 10:21 am

Re: Select statement issue with multiple where statement

Post by FatC »

Thanks so much...guess it was the single quotes that was missing. This is the statement that works:
$sql = "SELECT * FROM request WHERE date >= '$start' and date <= '$end'"
Post Reply