Jump to content

rbemiller

New Members
  • Posts

    6
  • Joined

  • Last visited

rbemiller's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks to everyone for your help. I was able to get it working properly. All i had to do was reference the mysql include again, inside the while loop. I was assuming that including it once would be sufficient. This is clearly a greet and highly active forum, and as I do more with php, I'm sure I'll be contributing here more often and I look forward to it. Here's the final working code: //get and format today's date $testdate = date('Y-m-d'); include("includes/databasedateretrieval.inc"); $dateverify = mysql_result($date_result,0,"1_day"); $dfresult = $dateverify; // Check for dating errors increment date by 1 day if W or H while ($dfresult == "W" || $dfresult == "H"){ $todaydate = strtotime($testdate); $todaydate = $todaydate + (24*60*60); $testdate = date("Y-m-d", $todaydate); include("includes/databasedateretrieval.inc"); $dateverify = mysql_result($date_result,0,"1_day"); $dfresult = $dateverify; } ?> <input type="text" name="businessdateofdeposit" value="<? echo date('m/d/Y', strtotime($testdate)); ?>" >
  2. I'll try to be more clear hear. The end result is to prepopulate a form field with today's date. However if "today" is a holiday (H) or a weekend (W), I need to make the date the next available non holiday or weekend...it must be a week day. We already have this database table set up for another function with all of the days of the year (in the bdod column) and a W or H for those that are a weekend or holiday (in the 1_day column). I simply want to do the following. When the page loads, create $testdate as today's date. Then, check the database to make sure $testdate doesn't fall on one of the weekend or holiday days. If it does, increment by one day, then check again if the new $testdate falls on a weekend or holiday. Once it no longer falls on a weekend or holiday, populate the form field with that value, as that will be the next available week day. I hope this clarifies a bit more. I'm not sure this is the best way, but I'm trying to leverage an existing database table which I cannot change.
  3. But my query contains a variable ($testdate), which is what I'm trying to increment during each loop. Wouldn't that mean the query is different every time? The query is: WHERE bdod = '$testdate'" So, if test date is different, it's going to look in a different row, b/c bdod contains a different day of the year in each row.
  4. Well, I'm not trying to update the database at all. Just query it, and make sure today's date doesn't fall on a designated W or H day...and if it does fall on one of those days, increment 1 more day, query again, and repeat until it doesn't. Make sense?
  5. What I failed to mention is that the included mysql includes a query with a WHERE clause that references the $testdate variable, which, I think, does get updated each time it loops. I do want to obtain the same row each time i run the query, but check it against an incremented $testdate.
  6. What I need to do is query a table based on a date. Then, if the query returns a "W" or an "H", I need to add one day to the date, then run the query again, until it doesn't return either a "W" or an "H". My code works fine when the initial query doesn't return a W or H, but when it does, it times out, seemingly in and endless loop. So clearly, something I'm doing with the loop isn't correct. Can someone help with my logic? Thanks very much from this first time visitor to PHP Freaks! Here's the code: <? $testdate = date("Y-m-d", strtotime("2012/09/30")); include("includes/databasedateretrieval.inc"); $dateverify = mysql_result($date_result,0,"1_day"); $dfresult = $dateverify; // Check for dating errors while ($dfresult == "W" || $dfresult == "H"){ //convert the date to time $todaydate = strtotime($testdate); //add 1 day to the date $todaydate = $todaydate + (24*60*60); //convert the date back to a format compatible with the table data $testdate = date("Y-m-d", $todaydate); //here I'm querying the table again to see if the new date returns a W or H $dateverify = mysql_result($date_result,0,"1_day"); $dfresult = $dateverify; } ?> <? echo $testdate; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.