View Full Version : PHP Question
Hi
At the moment, I have a thing on an air cadet website, which says:
The uniform for 12/10/09;
Working Blues
Now, they're both stored in a MYSQL database, and it fetches it from there. However, I have to manually update the date, and this is a bit anoying.
So is it possible to use PHP to automatically see what the date is for the next Monday or Friday, and produce it in a 6 digit date format?
Thanks
Luke
Johno
10-10-2009, 05:48 PM
The only way I can see of doing it is something like having another row in the MySQL DB (day - either monday or friday) then having something like this:
<?PHP
$mysql_day = mysql_query("SELECT day FROM uniform");
$spoons = date('d-m-Y', strtotime('next $mysql_day'));
echo $spoons;
?>
That code is totally horrible but I believe that is the kind of thing you would want, i.e.
date('d-m-Y', strtotime('next monday'));
Would give the date of the next monday.
The only way I can see of doing it is something like having another row in the MySQL DB (day - either monday or friday) then having something like this:
<?PHP
$mysql_day = mysql_query("SELECT day FROM uniform");
$spoons = date('d-m-Y', strtotime('next $mysql_day'));
echo $spoons;
?>
That code is totally horrible but I believe that is the kind of thing you would want, i.e.
date('d-m-Y', strtotime('next monday'));
Would give the date of the next monday.
Hey, Im pretty noobish at php,a nd don't fully understand that code, could you explain further ;p
BoyBetterKnow
10-10-2009, 06:12 PM
The only way I can see of doing it is something like having another row in the MySQL DB (day - either monday or friday) then having something like this:
<?PHP
$mysql_day = mysql_query("SELECT day FROM uniform");
$spoons = date('d-m-Y', strtotime('next $mysql_day'));
echo $spoons;
?>
That code is totally horrible but I believe that is the kind of thing you would want, i.e.
date('d-m-Y', strtotime('next monday'));Would give the date of the next monday.
yeh even though Johno made a few mistakes, strtotime is a good function. It converts a string time to a unix timestamp.
strtotime('24th September 2008');
Something like that or w/e
Right, just had a look at php.net - confused even more haha ;p
Soo, could someone help me, atm I have
echo (' The next uniform is $uniform[date]; ...');
etc
So, what have i got to replace that with?
Sorry for fuss xD
Luke
Johno
10-10-2009, 06:51 PM
Right okay, what I had here before didn't work haha. It should have given the date for monday. Im not the best at PHP haha. Im sure Protege will be able to give you a working method :)
Right, done that, but its showing the date as Friday, not monday :S
Update:
Sorry for double post
Swapped the thing around so it sayd if saturday||sunday etc
and it worked;
Many Thanks! and +rep if i can.
Luke
Instead of making another thread, decided just to post here again;
Anyways, it worked, until it got to today, and now, its showing next Monday instead of next friday..
Heres my code;
<?
if (date("l") == "saturday"||"sunday") {
$day = "monday";
} else {
$day = "friday";
}
$date = date('d/m/Y', strtotime("next $day"));
echo(" The uniform for $date<br /> • <i>$uniform[uniform[</i>");
?>
took out some of the unneccesary code
Protege
12-10-2009, 06:07 PM
<?php
if( date( 'l' ) == 'saturday' || date( 'l' ) == 'sunday' )
{
$day = 'monday';
}
else
{
$day = 'friday';
}
$date = date( 'd/m/Y', strtotime( "next {$day}" ) );
echo 'The uniform for ' . $date . '<br /> • <i>' . $uniform[ 'uniform' ] . '</i>';
?>
BoyBetterKnow
12-10-2009, 06:59 PM
<?php
if( date( 'l' ) == 'saturday' || date( 'l' ) == 'sunday' )
{
$day = 'monday';
}
else
{
$day = 'friday';
}
$date = date( 'd/m/Y', strtotime( "next {$day}" ) );
echo 'The uniform for ' . $date . '<br /> • <i>' . $uniform[ 'uniform' ] . '</i>';
?>
What's up with the spaces? :p
Protege
12-10-2009, 07:06 PM
I'll code it like you sir:
<?php
if(date('l')=='saturday'||date('l')=='sunday'){
$day='monday';
}else{
$day='friday';
}
$date=date('d/m/Y',strtotime("next {$day}"));
echo 'The uniform for '.$date.'<br /> • <i>'.$uniform[ 'uniform' ].'</i>';
?>
Enjoy your read.
That looks like its working brill; thanks!
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.