Jump to content

MoFish

Members
  • Content Count

    210
  • Joined

  • Last visited

Everything posted by MoFish

  1. Hi All, I have mark-up which contains many {{edit:xxx}} tags this is inside a variable called $html I'm trying to find all these edit tags and displaying the name, but am not sure best how to achive it. For example my $html contains: {{edit:top}} {{edit:bottom}} {{edit:left}} {{edit:right}} I want to create a $results array with the following values: top bottom left right Many thanks, MoFish
  2. Hi requinix, Thanks for your reply. I may look at parsing the document for items in double braces instead, hopefully that makes things a little simpler. Cheers, MoFish <img src='{{source}}' label='{{label}}' help="{{help}}" />
  3. Hi, I am trying to use DOMdocument to find <edit> tags in my HTML. When I use an <edit> tag on it's own it works fine and finds all the information I require On the odd occasion, I am required to put my <edit> tags inside quotes (as per my second example commented out) which falls over. I'm assuming it does not like the quotes and is bombing out Can anyone shed some light on if this is possible? or will this simply not work with the DOMdocument due to it's structure? I understand its' not the norm. Many Thanks, MoFish <?php // works $html = "<edit name='source' label='Source' help='boom' />"; // doesnt work // $html = "<img src='<edit name='source' label='Source' help="boom" />' />"; $dom = new DOMDocument(); $dom->loadHTML($html); $edits = $dom->getElementsByTagName('edit'); foreach ($edits as $edit) { foreach ($edit->attributes as $attr) { echo "Name '$attr->nodeName' | Value '$attr->nodeValue'<br />"; } } ?>
  4. Hi, I am looking to alter this slightly and am not sure how best to go around it. What I am now trying to do is: Set a start date e.g first day of January (2017-01-01) Set a end date e.g last day of December (2017-12-31) Find the number of weeks between the two date ranges (2017-01-01, 2017-12-31) which returns 52 weeks. And the tricky bit - for each of these 52 weeks - find the weeks startdate (Monday this week) and enddate (Friday this week). I have got the first three steps working using the function below, but am a little unsure on how best to find out the start date and end dates of these particular 52 weeks. I am maybe over thinking it, but i cannot understand gow best to tackle the next steps - as am unsure on how to find out a single date in each week. Any help much appriciated. MoFish function datediffInWeeks($start, $end) { if($start > $end) return datediffInWeeks($end, $start); $sd = DateTime::createFromFormat('Y-m-d', $start); $ed = DateTime::createFromFormat('Y-m-d', $end); return floor($sd->diff($ed)->days/7); // foreach of these weeks // find the start date 'Monday this week' // find the end date 'Friday this week' // return an array } var_dump(datediffInWeeks('2017-01-01', '2017-12-31')); // 52
  5. Hi Barand, Thats exactly what I needed. Thank you very much. MoFish
  6. Thanks, I think I have got the week calculation bit working after some messing around. I am trying to change my array slightly to 'group' the results into week numbers but am hitting some road blocks. I seem to get one week in the correct one, but not all of them I currently have: Array ( [0] => stdClass Object ( [SALE_ID] => 1 [SALE_DATE] => 2017-01-01 [SALE_WEEK] => 1 ) [1] => stdClass Object ( [SALE_ID] => 1 [SALE_DATE] => 2017-02-15 [SALE_WEEK] => 4 ) [2] => stdClass Object ( [SALE_ID] => 1 [SALE_DATE] => 2017-03-25 [SALE_WEEK] => 1 ) [3] => stdClass Object ( [SALE_ID] => 1 [SALE_DATE] => 2017-04-10 [SALE_WEEK] => 3 ) ) And would like to have something like the below - whereby I can loop out all the records based on the week. Array ( [week1] => stdClass Object ( [1] => stdClass Object ( [SALE_ID] => 1 [SALE_DATE] => 2017-01-01 [SALE_WEEK] => 1 ) [2] => stdClass Object ( [SALE_ID] => 1 [SALE_DATE] => 2017-03-25 [SALE_WEEK] => 1 ) ) [week3] => stdClass Object ( [1] => stdClass Object ( [SALE_ID] => 1 [SALE_DATE] => 2017-04-10 [SALE_WEEK] => 3 ) ) [week4] => stdClass Object ( [1] => stdClass Object ( [SALE_ID] => 1 [SALE_DATE] => 2017-02-15 [SALE_WEEK] => 4 ) ) ) At the moment I have: $results = array( array("SALE_ID"=>"1","SALE_DATE"=>"2017-01-01"), array("SALE_ID"=>"1","SALE_DATE"=>"2017-02-15"), array("SALE_ID"=>"1","SALE_DATE"=>"2017-03-25"), array("SALE_ID"=>"1","SALE_DATE"=>"2017-04-10") ); $obj = json_decode (json_encode ($results), FALSE); foreach ($obj as $r){ $date = new DateTime($r->SALE_DATE); $r->SALE_WEEK = $this->sale_model->week_calc($date); } Thanks, MoFish
  7. Thanks Barand, I've not been able to use the function successfully due to the information I'm passing in being incorrect. I'm not sure how best to format this. DB value: // 2017-02-17 00:00:00 Argument 1 passed to sale_model::week_number() must be an instance of DateTime
  8. Hi Requinix, Thanks for taking the time to respond. I have tried your example - but am getting the following when trying it with my code from value from the DB. Argument 1 passed to sale_model::week_number() must be an instance of DateTime The value is 2017-02-17 00:00:00 from the database - should this be amended before going into the function? Thanks, MoFish // return $return = $this->query("select * from SALE;", true); // foreach foreach ($return as $item){ echo $item->SALE_DATE; //2017-02-17 00:00:00 $week = $this->week_number($item->SALE_DATE); $item->week = $week; } // print_r ($item);
  9. Hi, I'm trying to associate a week number for a date I receive from my database. The week number is calculated between the last Friday of the previous month and the last Friday of the current month for that particular date. I would expect the week number to be 1,2,3 or in some cases maybe a 4 week month. I tried to use DatePeroid without much success, I've never used it before but feel im using it incorrectly as something is not quite right. Could anyone help? Regards, MoFish // try to find the week number foreach(new DatePeriod($rstart, new DateInterval('P1D'), $rend) as $date) { $item->SALE_WEEK_NUMBER = "Week".$date->format('W'); } The code below calculates the date ranges from the database date. // foreach foreach ($return as $item){ // month range start $rs = new DateTime($item->SALE_DATE, $time_zone); $rstart = $rs->modify('last friday of previous month'); echo "<br/><br/> Range Start: " . $rs->format('Y-m-d'); // month range date $re = new DateTime($item->SALE_DATE, $time_zone); $rend = $re->modify('last friday of this month'); echo "<br/> Range End: " . $re->format('Y-m-d'); // try to find the week number foreach(new DatePeriod($rstart, new DateInterval('P1D'), $rend) as $date) { $item->SALE_WEEK_NUMBER = "Week".$date->format('W'); } }
  10. Hi Barand, Thanks for this. This was not producing the results as I was expecting - however I have modified the query and this seems to be working now. SELECT * FROM TABLE WHERE `DDATE` BETWEEN (UTC_DATE() - INTERVAL 2 DAY) AND UTC_DATE() Thanks everyone for taking the time to respond. MoFish
  11. Hi requinex, Yes, I want all of the results. I have tried your query - however this is not working quite as expected. Maybe this will help explain what I'm trying to do: if TODAY is in the 3 DAY RANGE of DDATE value - then display results
  12. Jacques1 & requinex - Sorry about this. I'm still not getting the results I require. The following is still not returning the correct data - even without the -. I have attempted so many queries myself and none appear to be correct. SELECT * FROM TABLE WHERE DATE(`DDATE`) = DATE_ADD(UTC_DATE(), INTERVAL 3 DAY)
  13. Hi Requinex, Yes, I looked at your query - however noticed you had put a limit on the end of the query - which made me think we were talking about differing things. I could potentially expect more than one result as per my example results above. I have tried multiple times to do the 'middle bit' but am struggling a little. I thought my query above was close.
  14. Hi Requinix, Thanks for your reply. I may have not communicated correctly what I am trying to achieve - as there could often be more than one result. Let's say I have the following data in my TABLE and today's date is the 09/02/2017 ID, DDATE 1, 09/02/2017 (date/time) 2, 15/02/2017 (date/time) 3, 20/02/2017 (date/time) 4, 07/02/2017 (date/time) 5, 09/02/2017 (date/time) 6, 06/02/2017 (date/time) I would expect this to return the following results: ID, DDATE 1, 09/02/2017 (today) 4, 07/02/2017 (tomorrow - inside 3 day range) 5, 09/02/2017 (today) 6, 06/02/2017 (3rd day ago - inside 3 day range) I thought the SQL query would have been something like the following - however this does not work nor is it fully valid. // SELECT * FROM TABLE WHERE DATE IS BETWEEN TODAYS DATE AND TODAYS DATE + 3 DAYS SELECT * FROM TABLE WHERE (`DDATE` BETWEEN UTC_DATE() AND UTC_DATE() + 3 DAY INTERVAL); Regards, MoFish
  15. Hi requinex, I think in short terms yes. select where the current date matches the ddate where it is no more than 3 in the future.
  16. Hi, Another date query which I'm struggling with. Would anyone be able to help me at all? I have the following table. ID, DDATE 1, 09/02/2017 (date/time) 2, 15/02/2017 (date/time) 3, 20/02/2017 (date/time) I'm trying to only select the values from the DB where the CURRENTDATE is equal to the DDATE value + 3 days afterwards. For example: Once the CURRENDATE is 09/02/2017 it should return row 1 until the CURRENTDATE hits the 12/02/2017 as that's + 3 days. It should not return row 2 or 3 until the actual date (15/02/2017) or (20/02/2017) is the CURRENTDATE I tried this myself a few times and failed - the results are not correct. I used UTC_DATE() in my queries as my server is based in America and i'm in UK. Any help much appreciated. Thanks, MoFish SELECT * FROM `TABLE` WHERE `DDATE` = UTC_DATE() AND `DDATE` BETWEEN (DATE((`DDATE`) + INTERVAL 3 DAY) AND UTC_DATE()) SELECT * FROM `TABLE` WHERE (`DDATE`) BETWEEN UTC_DATE() AND (`DDATE`) + INTERVAL 3 DAY SELECT * FROM TABLE WHERE UTC_DATE() = DATE(`DDATE`) + 3 DAY INTERVAL
  17. Thanks for replying Barand. I have amended your query to suit my needs - the BETWEEN was the key i was missing i think. The following appears to work as expected for the time being - however i'm guessing when UK hits Brittish Summer Time then things may not work quite aswell. Until then, i'll leave it as it currently is. Thanks again, your a star. SELECT * from table WHERE UTC_DATE() BETWEEN DATE(`schedule_start`) AND DATE(`schedule_end`) AND UTC_TIME() BETWEEN `schedule_start` AND `schedule_end` MoFish
  18. Hi Barand, sorry to bother you again. I have amended things slightly to use a date/time field instead of a seperate date and time column as it was a bit of an overhead to maintain. My SQL query has been updated as below - however it doesnt appear to work correctly. To clarify on what i am trying to do: I only want to capture results between schedule_start and schedule_end on both the current date and time. i tried UTC_TIMESTAMP also without success. UTC_TIME was used as you mentioned before to help with the SQL TIME i had. The query does seem a little long winded. Regards, MoFish select * from `table` WHERE UTC_DATE() >= `schedule_start` AND UTC_DATE() <= `schedule_end` AND EXTRACT(HOUR_MINUTE FROM UTC_TIME()) >= EXTRACT(HOUR_MINUTE FROM schedule_start) AND EXTRACT(HOUR_MINUTE FROM UTC_TIME()) <= EXTRACT(HOUR_MINUTE FROM schedule_end)
  19. Thanks Barand, turns out my server was using an American timezone - darn! I used a set time_zone to Europe/London and all worked! Not sure if this is the best way to update it however. SET time_zone = 'Europe/London'; select * from `table` where CURDATE() >= `schedule_date_start` AND CURDATE() <= `schedule_date_end` AND EXTRACT(HOUR_MINUTE FROM CURTIME()) = EXTRACT(HOUR_MINUTE FROM schedule_time) Thanks very much! MoFish
  20. Thanks for replying Barand. I tried the following SQL which has no errors - however does not return the result i would have expected. select * from `table` where CURDATE() >= `schedule_date_start` AND CURDATE() <= `schedule_date_end` AND EXTRACT(HOUR_MINUTE FROM CURTIME()) = EXTRACT(HOUR_MINUTE FROM schedule_time) I set a row in my DB with the following values and waited until 17:06 before performing my query - however nothing was returned. If i remove the time bit you supplied - the correct date results are returned. schedule_date_start (date) schedule_date_end (date) schedule_time (time) 2017-01-11 2017-01-18 17:06:00 Is there something i am missing? Thanks, MoFish
  21. Sorry - I just noticed that there is a forum for MySQL Help. This should probably be there. Appologies!
  22. Hi All, I have the following DB structure. schedule_date_start | schedule_date_end | schedule_date_time 2017-01-11 | 2017-01-11 | 15:00:00 I am going trying to pefrom a query every minute to find out what items are found between the: schedule_date_start and schedule_date_end and match the schedule_date_time. I attempted to do this by writing the following SQL statement. I am finding that i never get any results. This is probably because my script executing is not running at exactly 15:00:00 and quite possibly 15:00:45. Is there an easy way to perform a query which would not take into consideration of the seconds? I tried messing around with the minutes() however didn't have much luck. select * from `domains` where CURDATE() >= `schedule_date_start` AND CURDATE() <= `schedule_date_end` AND CURTIME() = `schedule_time` Thanks, MoFish
  23. Hi Jacques, Thanks for that - worked perfect. I was using PHP before, however found that it exceeded my memory_limits on my server everytime it was zipping. The exec method seemed to be the only way it would zip without falling over. Cheers, MoFish
×
×
  • 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.