Page 1 of 1

Query By Weekend

Posted: Mon Feb 09, 2009 3:32 pm
by cupaball
i mistakenly put this in the database section.

Will the code below work? I want to, based on the date, show events for the current weekend. My database has a date feild and day feild.

Code: Select all

 
function show_weekend() {
 
$date = CURDATE();
$day_of_the_week = DAYOFMONTH($date);
 
if $day_of_week = '1'{
 
$date_range_1 = $date - 2;
 
 
$q = "SELECT `tb_events`.`event_title`, `tb_events`.`date`, `tb_events`.`info`\n"
    . "FROM `tb_events`\n"
    . "WHERE  (date BETWEEN $date AND $date_range_1) AND WHERE `tb_events`.`event_title` = 1, 6, 7\n"
    . "ORDER BY `tb_events`.`date` ASC\n"
    . " LIMIT 0, 30 ";
 
$result = $mysqli->query($q) or die($mysqli_error($mysqli));
 
if ($result) {
 
while($row = $result->fetch_object()) {
    $tile = $row->event_title;
    $date = $row->date;
    $info = $row->info;
 
print '<h3>'.$title.'</h3>
<p>'.$date.'</p>
<p>'.$info.'</p>
 
';
print "\n";
 
}
 
 
}
 
else if ($day_of_week = '2') {
 
 
$date_range_1 = $date + 4;
$date_range_2 = $date + 6;
 
 
$q = "SELECT `tb_events`.`event_title`, `tb_events`.`date`, `tb_events`.`info`\n"
    . "FROM `tb_events`\n"
    . "WHERE  (date BETWEEN $date_range_1 AND $date_range_2)\n"
    . "ORDER BY `tb_events`.`date` ASC\n"
    . " LIMIT 0, 30 ";
 
while($row = $result->fetch_object()) {
    $tile = $row->event_title;
    $date = $row->date;
    $info = $row->info;
 
print '<h3>'.$title.'</h3>
<p>'.$date.'</p>
<p>'.$info.'</p>
 
';
print "\n";
 
}
 
}
 
}
 

Re: Query By Weekend

Posted: Mon Feb 09, 2009 4:12 pm
by VladSun
Stop spamming with multiple threads for a single problem!
viewtopic.php?f=2&t=94879

Re: Query By Weekend

Posted: Mon Feb 09, 2009 4:48 pm
by cupaball
Wasn't it posted in the wrong area to begin with? I would have thought as the admin you would have move it to the right location.

Re: Query By Weekend

Posted: Mon Feb 09, 2009 4:50 pm
by VladSun
cupaball wrote:Wasn't it posted in the wrong area to begin with? I would have thought as the admin you would have move it to the right location.
No, it wasn't. Your problem is SQL related, not PHP.

And leave this decision to the moderators ;)

Re: Query By Weekend

Posted: Mon Feb 09, 2009 10:28 pm
by itp
2 errors in first three lines. (Maybe this was supposed to be pseudo-code?)

try: if ($day_of_week == '1')
$date = CURDATE(); not a PHP function, try: date("Ymd");

Re: Query By Weekend

Posted: Mon Feb 09, 2009 10:32 pm
by John Cartwright
Please do not create duplicate threads on the same topic.

Locked.