User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » mysql/php - what's wrong with this code??? Page [1]  
mytwocents
All American
20654 Posts
user info
edit post

I have a calendar/scheduling script that says (or should say) if today's date is greater than or equal to the 5th day of a certain month, but less than or equal to the 4th or the next month, then use a specific page, if not, then go to the next one..... So I have this for example:

$month = date("Y-m-j");
echo $month;
if ($month >= "2010-03-5" && $month <= "2010-04-4") {
include('may.php');
} else

if ($month >= "2010-04-5" && $month <= "2010-05-4") {
include('june.php');
} else


Based on this it should display june.php but it's not, it's displaying may.php ......?

4/12/2010 11:06:39 PM

skokiaan
All American
26447 Posts
user info
edit post

show us your face or tits first

4/12/2010 11:09:20 PM

moron
All American
34011 Posts
user info
edit post

i'm not a php programmer, but should that "j" be a "d" in the first line...?

4/12/2010 11:11:36 PM

mytwocents
All American
20654 Posts
user info
edit post

^^

^ 'j' means the day without the leading zeros......I've got it set so it's the YEAR - (4 digit), MONTH - (leading zero included) - DAY (no leading zeros) so today's date 2010-04-12

4/12/2010 11:16:55 PM

qntmfred
retired
40550 Posts
user info
edit post

consider using this kind of approach instead


<?php

$monthpages = array();
$monthpages[] = 'january.php';
$monthpages[] = 'february.php';
$monthpages[] = 'march.php';
$monthpages[] = 'april.php';
$monthpages[] = 'may.php';

$month = date("Y-m-j"); // get today's date
$t = strtotime($month); // get the numeric representation of today's date
$t = $t - 5*60*60*24; // subtract five days from today's date
$monthindex = date("n", $t); // get the month of 5 days ago

echo $monthpages[$monthindex - 1]; // oh look, the month corresponds to the index in the array

?>


[Edited on April 12, 2010 at 11:35 PM. Reason : i assume the problem is b/c you're doing string comparison up there, not date comparison]

4/12/2010 11:34:07 PM

qntmfred
retired
40550 Posts
user info
edit post

if ("2010-04-12" >= "2010-03-5" && "2010-04-12" <= "2010-04-4")

[Edited on April 12, 2010 at 11:53 PM. Reason : looks like true && true to me]

4/12/2010 11:53:10 PM

kiljadn
All American
44689 Posts
user info
edit post

Yeah I was wondering why you weren't using an array here.

4/12/2010 11:53:20 PM

mytwocents
All American
20654 Posts
user info
edit post

yes qt! well sorta....that makes sense why it wouldn't work (date comparison not string comparison)

But.....it looks like the formula is a set formula (i.e. subtracting days in relation to the current date) but that won't work because if someone comes to the page on April 5 OR May 4, they'd get june.php....so it's not just a matter of adding days, hence the 'between' certain dates thing....?

^and I was told an array was the better way to go but didn't know how to write it

[Edited on April 13, 2010 at 12:01 AM. Reason : k ]

4/13/2010 12:00:34 AM

qntmfred
retired
40550 Posts
user info
edit post

well if it's a formula, you can program it

4/13/2010 12:01:53 AM

Stein
All American
19842 Posts
user info
edit post

Use date('Ymd'), then your >= and <= will actually work properly.

Then you can just do:

if (($month >= 20100305) && ($month <= 20100404))

With qntmfred's code sample, you can use functions like mkdate() to simplify adding and subtracting dates.

4/13/2010 12:02:11 AM

mytwocents
All American
20654 Posts
user info
edit post

thx you all I barely know php/mysql as it is so I doubt I could write a formula....and I know an array would be better, but for the time being, I've done what Stein has suggested and it's working great Thanks you guys

4/13/2010 12:26:40 AM

evan
All American
27701 Posts
user info
edit post

well shit, i got here too late.

4/13/2010 12:58:54 AM

mytwocents
All American
20654 Posts
user info
edit post



I mean shit, I got plenty of questions that come up if you get bored....this can be my thread for my stupid code questions

[Edited on April 13, 2010 at 1:35 AM. Reason : ]

4/13/2010 1:34:14 AM

gs7
All American
2354 Posts
user info
edit post

Quote :
"stupid code questions"


I'd much rather answer these than read about the latest technology bitchfest.

4/13/2010 6:13:50 AM

Ernie
All American
45943 Posts
user info
edit post

Read a damn book or something already

I mean damn

4/13/2010 8:36:30 AM

Shaggy
All American
17820 Posts
user info
edit post

Quote :
"mysql/php"

found your problem

4/13/2010 10:04:38 AM

FroshKiller
All American
51908 Posts
user info
edit post

ya you should totally be using ruby on rails

4/13/2010 10:06:45 AM

Shaggy
All American
17820 Posts
user info
edit post

ruby on rails manages to be worse than php, which is a pretty amazing accomplishment.

4/13/2010 10:12:24 AM

DeltaBeta
All American
9417 Posts
user info
edit post

Shaggy refuses to write any sort of code or script in anything other than binary.

4/13/2010 10:58:13 AM

Shaggy
All American
17820 Posts
user info
edit post

java or c# are the only languages worth knowing these days.

4/13/2010 1:48:06 PM

Golovko
All American
27023 Posts
user info
edit post

also, I'd like to add that IE is the only real browser. If it works in IE that is enough.

4/13/2010 2:23:22 PM

Shaggy
All American
17820 Posts
user info
edit post

^ yep. Better get ready for IE9 tho. If it doesnt work in IE then it doesnt work.

4/13/2010 2:26:57 PM

Golovko
All American
27023 Posts
user info
edit post

I don't know about IE9. Sounds like MS is moving into some sort of standard that others follow and that is not an IE tradition. I'm going to stick with IE6 for now since that is more or less the last browser to get it right.

4/13/2010 2:28:34 PM

Shaggy
All American
17820 Posts
user info
edit post

IE9 is going to be good cause its only going to implement the features of html5 that are worthwhile. Which owns. Silverlight owns too.

4/13/2010 2:32:39 PM

Golovko
All American
27023 Posts
user info
edit post

You should start a blog so we can keep up with trends. I've wasted so much time supporting inferior browsers to IE because I thought I had to, you could have saved me a lot of time and pain.

4/13/2010 2:34:05 PM

Shaggy
All American
17820 Posts
user info
edit post

im just trying to help out where i can. If you write anything having to do with html/css/js by hand you're really pretty bad, and unless you're an irl designer w/ like a design degree and a bunch of other stuff you probably did it wrong.

protip: Use java/c# for the backend and ui component code, and then have your designers skin it.

oh yea, also unless you're doing something that doesnt matter at all, sql server for the database server.

mysql, lol, what a joek.

4/13/2010 2:37:41 PM

Golovko
All American
27023 Posts
user info
edit post

Thanks, much appreciated!

4/13/2010 2:41:06 PM

Talage
All American
5091 Posts
user info
edit post

I think I got dumber reading the last 8 posts in here.

4/13/2010 10:04:54 PM

qntmfred
retired
40550 Posts
user info
edit post

we all got dumber Talage. we all got dumber.

4/13/2010 10:08:56 PM

mytwocents
All American
20654 Posts
user info
edit post


soooooooo...........IE, java, and C = awesome

php, mysql, firefox = the worst shit evah


right?

4/13/2010 10:14:42 PM

Golovko
All American
27023 Posts
user info
edit post

^you got it! Glad to see shaggy is helping more users than just me!

4/13/2010 10:17:26 PM

evan
All American
27701 Posts
user info
edit post

extremely obvious trolling ITT

4/14/2010 8:38:24 AM

Shaggy
All American
17820 Posts
user info
edit post

not even trolling. all languages that start with p are shit and mysql is awful.

html/js/css are the languages of idiots, and if you find yourself spending alot of time there (and you aren't a framework developer) you should probably rethink your life. Maybe read up on some modern c# MVC stuff, or if you still want to hate yourself a little try richfaces.

html is a total joke and html5 isn't worth learning, especially when you dont know what parts IE9 is gonna support. tbqh http is really only useful as a transport for SOAP, and you should be writing your clients in silverlight.

4/14/2010 9:28:32 AM

Golovko
All American
27023 Posts
user info
edit post

I sometimes wonder if shaggy is employed and who employed him. Knowledge like that should not go unnoticed.

[Edited on April 14, 2010 at 9:33 AM. Reason : .]

4/14/2010 9:32:33 AM

gs7
All American
2354 Posts
user info
edit post

4/14/2010 9:39:07 AM

kiljadn
All American
44689 Posts
user info
edit post

the best trolls never admit to trolling

4/14/2010 7:11:26 PM

 Message Boards » Tech Talk » mysql/php - what's wrong with this code??? Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.