-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
Complicated Date/Job Frequency calculation problem.
.josh replied to moonman89's topic in PHP Coding Help
hmm...are you sure that query is right? thinking maybe it should be SELECT * FROM `dates` WHERE DATEDIFF('2009-07-01', start_date) = frequency -
Complicated Date/Job Frequency calculation problem.
.josh replied to moonman89's topic in PHP Coding Help
If I understood you correctly... // example array of data. build from db query $jobs[] = array('startDate' => "2009-01-01", 'frequency' => 2); $jobs[] = array('startDate' => "2009-03-25", 'frequency' => 30); $jobs[] = array('startDate' => "2009-06-14", 'frequency' => 12); $jobs[] = array('startDate' => "2009-07-14", 'frequency' => 14); $jobs[] = array('startDate' => "2009-07-25", 'frequency' => 3); // target date $tdate = "2009-07-28"; $date = strtotime($tdate); // foreach job... foreach($jobs as $job) { // get the timestamp for startDate + frequency days in future $jsD = strtotime($job['startDate']); $cDate = mktime(0, 0, 0, date("m",$jsD), date("d",$jsD)+$job['frequency'], date("Y",$jsD)); // if dates match up... if ($cDate == $date) // add to list $targetDates[] = $job['startDate']; } // end foreach // dump out data and results echo "<pre>"; print_r($jobs); echo "target date: " . $tdate . "<br/>"; print_r($targetDates); output: Array ( [0] => Array ( [startDate] => 2009-01-01 [frequency] => 2 ) [1] => Array ( [startDate] => 2009-03-25 [frequency] => 30 ) [2] => Array ( [startDate] => 2009-06-14 [frequency] => 12 ) [3] => Array ( [startDate] => 2009-07-14 [frequency] => 14 ) [4] => Array ( [startDate] => 2009-07-25 [frequency] => 3 ) ) target date: 2009-07-28 Array ( [0] => 2009-07-14 [1] => 2009-07-25 ) -
If you look in the opening form tag, you can see what method the form is, by looking for the method=".." attribute. it will either say "get" or "post"
-
exactly. The thing that makes wikis popular is the same thing that is its biggest thorn. Double edged sword. It is popular because anybody can contribute, yes. But at the end of the day, nobody uses it as a real resource. 100% free speech == 100% white noise.
-
So, how many lines are you up to with this now? I counted about 100 in the 3-code post you posted earlier. And you still have a bit more work to do. At the very least I see that you need to make your output some level of pretty. Judging by the rest of your code, I put you at about 125 lines. That's not too bad for someone who claims to be a complete noob. Once you finish and are not stressing anymore is the best time to go back and see if you can't streamline it a bit. Look for patterns. Do you see pieces of code that appear multiple times throughout your script? Good possibility it can be condensed.
-
[SOLVED] problem with sessions and forgetful array
.josh replied to caughtinweb's topic in PHP Coding Help
<a href='addbead.php'>add this bead</a> <?php session_start(); $_SESSION['wantlist'][] = $beadiwant; ?> that's pretty much it. No conditions, nothin'. Idea is that if the user clicks the button, add the bead to the list. Of course, first code (link) will be more complex, depending on how you are passing $beadiwant to the 2nd page. But principle is still the same. -
That's kind of what the main site is for, though it is still a work in progress, officially lacking some features in the works/on the drawing board. Some things are best resourced as tutorials. Some as blogs. Some things in a faq, some as a code repository. We are even working toward a system much like a wiki, where a broader range of people can contribute, without opening the floodgates.
-
I have to disagree with some of what you posted xtopolis. The assignment does not ask for him to validate or sanitize anything. Don't make it more complicated than it needs to be. Yes, in a real world application, it needs to be considered, just like a bunch of other things not listed in the assignment. But your advice applies even to this: don't take it all in big chunks.
-
I don't feel they are asking too much, if you have covered the absolute basics already, such as syntax rules. That's actually a pretty easy program to make, compared to how complex things can be. There are plenty of hints in there for what functions to use to accomplish the task. http://www.php.net/ is your best friend. All you have to do is http://www.php.net/somekeyword and it will try to find the closest function relevant for you. Then all you have to do is read what it does, how to use it (very easy to read explanation and examples). Just read the assignment carefully. Break it down into individual tasks. Sum it up into keywords. use them with php.net. Also, it might help to tell you that you can do this in 40-60 lines of code. Maybe less, depending on how pretty you want to make it.
-
Function for adding the "th", "rd", "nd", or "st" to a number?
.josh replied to mishasoni's topic in PHP Coding Help
-
research using SUM and GROUP BY in your mysql query
-
yes, I am. The not nice version would be more like this:
-
sure, I'll walk you through it...walk you to the nearest bookstore, that is. I suggest you get yourself a good php for beginner's book and start on page 1.
-
Function for adding the "th", "rd", "nd", or "st" to a number?
.josh replied to mishasoni's topic in PHP Coding Help
play_ yours may not show the th on 0 but what yours doesn't consider is that only numbers ending in '11' use th so it's 21st, 22nd, 23rd..31st,32nd,33rd, etc.... -
Function for adding the "th", "rd", "nd", or "st" to a number?
.josh replied to mishasoni's topic in PHP Coding Help
Okay I thought about it and I think I got everybody beat, even myself: date has a built-in way of determining the ordinal (I researched and found out the real name, though I see others already posted it!), so why not exploit that? function addOrdinal($num=0){return $num.(((strlen($num)>1)&&(substr($num,-2,1)=='1'))?'th':date("S",mktime(0,0,0,0,substr($num,-1),0)));} -
How to increment variable as the current year changes?
.josh replied to mishasoni's topic in PHP Coding Help
see the thread you made about it. -
Function for adding the "th", "rd", "nd", or "st" to a number?
.josh replied to mishasoni's topic in PHP Coding Help
function addCardinal($num = 0) { // I think that's what those things are called... $array = ((strlen($num) > 1) && (substr($num,-2,1) == '1'))? array('th','th','th','th','th','th','th','th','th','th') : array('th','st','nd','rd','th','th','th','th','th','th'); return $num . $array[substr($num,-1)]; } // end function addCardinal maybe shorter way to do it. First attempt. -
[SOLVED] Can someone have a look at this for me please?
.josh replied to Mardoxx's topic in PHP Coding Help
$ids = array(1,2,3); while($row = mysql_fetch_assoc($result)) { if (in_array($row['id'],$ids)) { // id is in $ids, do something } else { // id is not in $ids, do something } } -
You can turn your error reporting off by using error_reporting and/or display_errors but the better route would be to write something to do something with the error instead...
-
Well I don't see any form so I can't verify, but I assume by checkbox you mean radio buttons? Why not just put the subject as the radio button value and just do $subject = $_POST['subject']; // or whatever the radio button is named
-
[SOLVED] Can someone have a look at this for me please?
.josh replied to Mardoxx's topic in PHP Coding Help
what exactly are you trying to accomplish? -
Okay so this is the part where you have to actually make an effort and read.
-
http://www.phpfreaks.com/tutorial/php-add-text-to-image using $_SERVER['REMOTE_ADDR']
-
[SOLVED] is there any way to open a new window from a header
.josh replied to shadiadiph's topic in PHP Coding Help
It is not possible to open up a new window with php. php is a server-side scripting language. Only way to do that is to have php send out clientside markup or coding (like js) to do it. -
http://www.phpfreaks.com/forums/index.php/topic,105245.0.html One mentioned in that thread is by far (by a loooong shot) the most definitive and thorough book out there. If you are serious about buying a book, don't bother getting any other one.