Jump to content

Barand

Moderators
  • Posts

    24,356
  • Joined

  • Last visited

  • Days Won

    798

Everything posted by Barand

  1. try $data = [ 'A98-1', 'A99-1', 'A2000-1', 'A2003-1', 'A2006-1', 'A2007-1', 'A2009-1', 'A2010-10', 'A2010-9', 'A2010-8', 'A2010-7', 'A2010-6', 'A2010-5', 'A2010-4', 'A2010-3', 'A2010-2', 'A2010-1' ]; usort ($data, function($a, $b) { list($a1,$a2) = explode('-', $a); list($b1,$b2) = explode('-', $b); $x = strnatcmp($b1, $a1); if ($x==0) { return strnatcmp($b2,$a2); } return $x; }); Results: Array ( [0] => A2010-10 [1] => A2010-9 [2] => A2010-8 [3] => A2010-7 [4] => A2010-6 [5] => A2010-5 [6] => A2010-4 [7] => A2010-3 [8] => A2010-2 [9] => A2010-1 [10] => A2009-1 [11] => A2007-1 [12] => A2006-1 [13] => A2003-1 [14] => A2000-1 [15] => A99-1 [16] => A98-1 )
  2. Unfortunately for you, not all appear to be reversed. I have spotted a dozen in the above data that seem to be the correct way round (although in the North Atlantic). For example, the first three that are visible in the above image.
  3. You didn't say if key names were required or not, so you want either while( $rs_location = $rs_locations->fetch_assoc() ) { $markers[] = $rs_location; } or while( $rs_location = $rs_locations->fetch_row() ) { $markers[] = $rs_location; } followed by $json = json_encode($markers);
  4. Google took me to this one (amongst others) https://msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx
  5. Find any elements with id attribute = 'category' $elements = $xpath->query("*[@id='category']"); Find "p" elements anywhere in the document with id attribute = 'category' $elements = $xpath->query("//p[@id='category']"); As stated, an id should be unique, so either method should do it
  6. @ginerjm The "@" in that code tells xpath that "id" is an attribute. RTFM
  7. It implies that each queue has a separate table. But as you don't care to share the table structure with us, that can only be an assumption. So I'll not waste any more time and wish you luck.
  8. First of all, whenever I see names like queue_test queue_test2 then alarm bells start ringing to alert of bad design. What is the current structure of those "queue_test" tables?
  9. Then read the reply - I have told you how. Yes you are, you just don't realize it.
  10. Why waste time converting to an unusable date format? You cannot correctly compare dates in formats other than yyyy-mm-dd. (08/01/2015 is greater than 07/01/2016) Use ... AND date_start BETWEEN '2016-07-01' AND '2016-07-31' As for your other problem, remove the "invoice_total != 0" from the where clause and use it in a case statement when calculating the 30%
  11. Change the ["gif", "jpg", "png"] to array("gif", "jpg", "png")
  12. Use the expression instead of its alias in the calculation. SELECT SUM(invoice - estimate) / SUM(estimate) * 100 as percent Note SUM(estimate) and not COUNT. Multiplying an average by 100 is not the best way.
  13. Whatever was in the first $result variable has now neen overwritten later on. Also, your original (posted) result output had no League property, but it did have TeamLeagueStanding
  14. Do you think $results should be $result, perhaps?
  15. does this help? $html = '<html>'; $html .= <<<EOD <p>Hello</p> <div> <p class="p" data-id="3"></p> <p class="p" data-id="2"></p> </div> <div> <p class="p" data-id="1"></p> <div> <p class="p" data-id="2"></p> </div> </div> EOD; $html .= '</html>'; $x = simplexml_load_string($html); $counts = array_fill_keys(range(1,4),0); foreach ($x->xpath('//p[@class="p"]') as $p) { $id = intval($p['data-id']); $counts[$id]++; } echo '<pre>' . print_r($counts, 1) . '</pre>';
  16. try something like this $deadline = '2016-07-16 00:00:00'; // database datetime format $dtObj = (new DateTime($deadline))->modify('+1 days'); echo countdown($dtObj); //---> 1 day 11 hours 37 minutes 23 seconds function countdown(DateTime $dt) { $periods = [ 'days' => 'day', 'h' => 'hour', 'i' => 'minute', 's' => 'second', ]; $now = new DateTime(); $res = $now > $dt ? 'MINUS' : ''; $diff = $dt->diff($now); foreach ($periods as $p=>$per) { $v = $diff->$p; $plural = $v==1 ? '' : 's'; $res .= " $v $per$plural"; } return $res; } Alternatively, you can use SQL SELECT deadline , TIMESTAMPDIFF(DAY, NOW(), deadline) as days , MOD(TIMESTAMPDIFF(HOUR, NOW(), deadline) , 24) as hours , MOD(TIMESTAMPDIFF(MINUTE, NOW(), deadline) , 60) as minutes , MOD(TIMESTAMPDIFF(SECOND, NOW(), deadline) , 60) as seconds , SEC_TO_TIME(TIMESTAMPDIFF(SECOND, NOW(), deadline)) as hms FROM datetest; +---------------------+------+-------+---------+---------+-----------+ | deadline | days | hours | minutes | seconds | hms | +---------------------+------+-------+---------+---------+-----------+ | 2016-08-01 00:00:00 | 16 | 11 | 2 | 2 | 395:02:02 | | 2016-07-15 00:00:00 | 0 | -12 | -57 | -58 | -12:57:58 | | 2016-07-20 00:00:00 | 4 | 11 | 2 | 2 | 107:02:02 | | 2016-07-20 18:00:00 | 5 | 5 | 2 | 2 | 125:02:02 | +---------------------+------+-------+---------+---------+-----------+
  17. Yes! approx 30 emails from the site sitting in my inbox.
  18. Are notification emails going to be brought back too?
  19. You would use a loop somehting like this to get the data for insertion into your database table foreach ($results->TeamLeagueStanding as $team) { $team = $team->Team; $teamid = $team->Team_Id; $played = $team->Played; $playedathome = $team->PlayedAtHome; $playedathome = $team->PlayedAway; $won = $team->Won; $draw = $team->Draw; $lost = $team->Lost; $shots = $team->NumberOfShots; $yellowcards = $team->YellowCards; $redcards = $team->RedCards; $goalsfor = $team->Goals_For; $goalsagainst = $team->Goals_Against; $goaldiff = $team->Goal_Difference; $points = $team->Points; // INSERT query goes here } NOTE: some of those fields are redundant, namely played, goaldiff and points. played = playedhome + playedaway goaldiff = goalsfor - goalsagainst points = ( wins * 3 ) + draws
  20. That's the puzzling thing - according to the last four lines in the code (initial post) they are quoted
  21. Comparing the error messages, the first error (2013) is "undefined offset" and the second (year) is "undefined index". So it looks as though 2013 is interpreted as a numeric column number instead of an alpha key.
  22. try echo '<pre>' . print_r($row, true) . '</pre>'; That should show what indexes you do have in a $row array
  23. Your results will have a $row['year'] column. 2013, 2014 etc will be values in that column EDIT: Sorry, didn't scroll down far enough to see the "pivot" keyword in your query.
  24. I would be inclined to load the xml data into a temporary mysql table and then simply use an update query to change the prices in your main table. UPDATE product INNER JOIN tempproduct USING (product_id) SET product.price = tempproduct.price
  25. Here's an example $datax = "<eshop> <product> <id>35</id> <name>aaaaa</name> <price>50.00</price> </product> <product> <id>20</id> <name>bbbb</name> <price>100.00</price> </product> <product> <id>44</id> <name>ccccc</name> <price>70.00</price> </product> </eshop>"; $x = simplexml_load_string($datax); $prods = $x->xpath("//product[id=20]"); // find products with id = 20 echo $prods[0]->price; //--> 100.00
×
×
  • 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.