Page 1 of 1

Select statement issue with multiple where statement

Posted: Tue Dec 29, 2009 10:40 am
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>


<?
}

?>

Re: Select statement issue with multiple where statement

Posted: Tue Dec 29, 2009 10:44 am
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

Re: Select statement issue with multiple where statement

Posted: Tue Dec 29, 2009 11:36 am
by AbraCadaver
--Or--

Code: Select all

$sql = "SELECT * FROM `request` WHERE `date` BETWEEN '$start' AND '$end'";

Re: Select statement issue with multiple where statement

Posted: Tue Dec 29, 2009 11:39 am
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'"