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
cupaball
Forum Commoner
Posts: 85 Joined: Sun Feb 12, 2006 1:46 pm
Post
by cupaball » Mon Feb 09, 2009 3:32 pm
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";
}
}
}
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Mon Feb 09, 2009 4:12 pm
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
Post
by cupaball » Mon Feb 09, 2009 4:48 pm
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.
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Mon Feb 09, 2009 4:50 pm
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
Post
by itp » Mon Feb 09, 2009 10:28 pm
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");
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Feb 09, 2009 10:32 pm
Please do not create duplicate threads on the same topic.
Locked.