
The lack of two player co-op play for the story mode is a massive oversight and I just can’t understand why it hasn’t been implemented. Sillothian about Marvel Super Hero Squad: The Infinity Gauntlet |
Author | Reply | ||
Right then. Trying to find out whether a specified date string (in the format YYYYMMDD) falls between two other dates in the same format. You'd think this would be pretty simple in PHP but pretty much everything I've tried doesn't work predictably... So what am I doing wrong? So far I've done stuff along the lines of $today = strtotime(date(Ymd)) then if $today > $enddate then do something else if $today < $startdate then do something else... but it doesn't seem to recognise that my date falls between two days. Any help muchly appreciated. |
|||
| |||
Hmm strtotime should work perfectly. I've done something similar but I used: $today = date ("Y-m-d H:i:s"); $today = strtotime($today); And then did my comparisons. |
|||
| |||
I'm trying to avoid over-complicating the date string so a YYYYMMDD one was what I was after. Basically the date will be put in by an academic, so keeping it as simple as poss is pretty much the only option. Strtotime on that string seems OK, it's just when I run the comparisons the fucking thing ignores what I'm asking it to do. |
|||
| |||
Hmm the only thing I can think is that maybe strtotime requires some kind of a seperator between the datal elements, but then again it's an extremely powerful function and lets you use strings such as "4 days" "tomorrow" or "yesterday" so you'd think it'd be OK with what you're trying to do. |
|||
| |||
Tried it with a separated date/time format and it still gives the same results. Bah...could just be the syntax of my switch case statement but it LOOKS right... |
|||
| |||
if $today > $enddate then do something else if $today < $startdate then do something else... to me, that reads as "if today is after enddate, do something, if today is before startdate, do something else", so if today is between startdate and enddate then no condition will be met. to check if a date is between 2 dates you want something like: if(mydate >= startdate and mydate |
|||
| |||
Wanna paste or send me your code and I'll have a look? It sounds like one of those issues where it'll be something so minor that you can't see it. :) |
|||
| |||
Solved it. Went back to basics with if elseif else rather than case-switch. So yeah, it was one of my "blonde" moments I think - where I thought the solution was more complicated than it actually was. Ah well, simplest solutions are often the best. Ta though. |
|||
| |||
Gnnn! I thought I knew how to do this. Say I want to trim everything in a string after a separator character - for instance - I have a string that says "I suck from the cock of goats, I am a bad person" and I want to chop the end off that string after the comma. I thought it was "explode" but I can't seem to get that to work. Bear in mind the string's part of an array which could be why explode doesn't work... Any ideas, geniuses? |
|||
| |||
| |||
He's right too. It's a lovely "lazy programmers" language. I can't code in anything properly OOP to save my life, but knocking together PHP is (usually) pretty easy and gives you more or less instant results. |
|||
| |||
I'm not a PHP expert, but in most languages you'd use the index and substr functions, like: $input="one,two" $chopped=substr($input,0, index($input,",")); In other words, get the text from the beginning of the string up to (but not including) the character where the first comma is. Or if you've got regular expressions, you could do: $input="one,two" $chopped=$input $chopped=~s/,.*$// Which means 'replace a comma followed by stuff with nothing'. If you want to remove the final comma in a sentence, then that's a bit different - basically, what do you want to do with the string 'one, two, three'? Chop off 'two, three' or leave 'two' there? |
|||
| |||
That's the line of thinking I was working to, but it's a series of unequal length strings I'm chopping - Basically their common factor is that there's text after a comma that I want to chop but I can't use a strlen or substr type dealio to chop stuff, as I'm not always able to predict which characters to chop / show |
|||
| |||
Why not? The index function deals with variable length strings by finding where the comma is every time you give it a string. |
|||
| |||
aye, and you can probably do a reverse index if you just want to hit the last instance of a character in a string like "1,2,3,4" |
|||
| |||
Use Split function. It splits a sting into an array of elements based on a delimiter. I use it all the time to parse input lines from csv files :) |
|||
| |||
BINGO that's the kiddie...cheers JH! |
|||
| |||
Lack of sleep is really fucking me up but I should know this! Say a person had to enter 5 numbers into a database record. Is there any way of ensuring that the person hasn't entered 5 numbers the same (ie each number is unique?) without it interfering with all the other records (so using unique key for each field value is out) ? |
|||
| |||
Not sure I quite understand your question but can't you just query each entry and if that number already exists spit out an error message? That sounds way too obvious an answer and makes me think I've misunderstood your initial question. |
|||
| |||
No that is what I'm doing at the moment, I just thought there might be a neat way of doing it within the database itself so it got all pissy about non-unique entries. Not to worry, I'll just carry on with the PHP form validation route. Ta. |
|||
| |||
Back to those magic 5 numbers again but this time it's comparing 5 fields to ensure that no more than three of the fields have the same value. So for instance, if a student picked 5 course fields, I want it to squeak if that student's chosen more than three projects from the same course code - ie 5 civils projects instead of 3. Any ideas? Is there a way to make strcomp work for more than 2 strings? |
|||
| |||
The only way I can think to do it is to just compare each string with each other string. So compare 1 with 2 3 4 5 then 2 with 3 4 5 then 3 with 4 and 5 etc etc. |
|||
| |||
Was worried you might say that :) That was my original thought on how to do this. Bums, sounds like I'm going to have a lot of work ahead :( |
|||
| |||
The other way of doing it is to limit the choices in the drop down boxes once the maximum number in each category has been selected. But that makes your form a 5 stage submit process. |
|||
| |||
Sadly this is a bit more than just stopping 'em choosing less than three of the same course fields as they're held in a separate table. What I've ended up doing is a comparison matrix that extracts the 5 choice numbers and does a row by row lookup on them for the course codes, then compares all 5 course codes - TWICE (because there are two course codes per choice) just to find out which students didn't bloody listen when they were told not to oversubscribe certain course types. Fucking nightmare. I'm completely maths blind but this has been one of the most complicated bits of code I've ever written. The bastard works though, and the person who requested it can't quite believe I managed to do it in an afternoon. There's probably some incredibly simple way to do it that someone with a genius streak would find, but fuck it, it works :) /polishes stealth_coding_ninja badge. |
|||
|