Jump to content

MoFish

Members
  • Content Count

    210
  • Joined

  • Last visited

Community Reputation

0 Neutral

About MoFish

  • Rank
    Advanced Member

Profile Information

  • Gender
    Not Telling
  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.
×
×
  • 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.