Query By Weekend

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

Locked
cupaball
Forum Commoner
Posts: 85
Joined: Sun Feb 12, 2006 1:46 pm

Query By Weekend

Post 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";
 
}
 
}
 
}
 
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Query By Weekend

Post by VladSun »

Stop spamming with multiple threads for a single problem!
viewtopic.php?f=2&t=94879
There are 10 types of people in this world, those who understand binary and those who don't
cupaball
Forum Commoner
Posts: 85
Joined: Sun Feb 12, 2006 1:46 pm

Re: Query By Weekend

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Query By Weekend

Post 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 ;)
There are 10 types of people in this world, those who understand binary and those who don't
itp
Forum Commoner
Posts: 67
Joined: Fri Jun 15, 2007 6:50 am

Re: Query By Weekend

Post 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");
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Query By Weekend

Post by John Cartwright »

Please do not create duplicate threads on the same topic.

Locked.
Locked