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>
<?
}
?>
Select statement issue with multiple where statement
Moderator: General Moderators
Select statement issue with multiple where statement
Last edited by FatC on Tue Dec 29, 2009 11:40 am, edited 1 time in total.
Re: Select statement issue with multiple where statement
Try with:
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
Code: Select all
SELECT * FROM request WHERE `date` >= '$start' AND `date` <= '$end'- 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
--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.
Re: Select statement issue with multiple where statement
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'"