PDA

View Full Version : Creating an if statment in a WHERE on a Query


el-es-dee
03-24-2005, 03:51 PM
So, I figured out what I need, but I can't exactly figure out how to code it right.


$passed_year = date("Y");
$passed_day = date("j");
$passed_month = date("n");

$query = 'SELECT * FROM bt_shows WHERE year = '.$passed_year.' AND month >= '.$passed_month.' ORDER BY year ASC, month, day LIMIT '.($o*$nb).','.$nb;


It's not working correctly for a number of reasons.

1) it can't do when the day has passed, 2 ands seem to make it give SQL errors on that line..

2) it also doesn't compensate for when there is a show from another year (say 2006) in a month that = 2 or somthing (because that month has passed...)

So, basicly, I need it to only display anything that is after today's date.

what this is for is some one that has shows and needs to add shows to his website of when he is going to be playing.

Would this be days easier if I just had a "date" field rather then a "Year, Month, Day" field in MySql... also, is it posible to have it still sort numericly if the numbers are entered like mm/dd/yyyy ? Even that way, I see still facing the same prolems as I am right now with number 2...

Right now, my loop for displaying the code looks like this


while($row = mysql_fetch_array($res)) {
echo('<table width="175" height="30" border="0" class="show">
<tr>
<td id="place">
<a href="tours.php?veniew_id='.$row['post_id'].'">
'.$row['veniew'].'
'.$row['month'].'/'.$row['day'].'
</a></td></tr></table>');
}


is there some kind of if() or while() I can add there to make it work?

Thanks again

-phpn00b

also, the way suguested to me by scoutt before was



if (($row['month']. '/' .$row['day']. '/' .$row['year']) != date("n/j/Y"))


but it didn't quite work because it pulled things that weren't equal to the current date and still displayed events that had passed. I tried to toy with it a bit, but it just made me want to throw my laptop =X

scoutt
03-24-2005, 04:27 PM
Originally posted by el-es-dee

Would this be days easier if I just had a "date" field rather then a "Year, Month, Day" field in MySql... also, is it posible to have it still sort numericly if the numbers are entered like mm/dd/yyyy ? Even that way, I see still facing the same prolems as I am right now with number 2...


most definately. but I would use timestamps from php. you can then go to any date ot form any date. you can search any date as well.