Jump to content

Barand

Moderators
  • Posts

    24,612
  • Joined

  • Last visited

  • Days Won

    834

Everything posted by Barand

  1. @ginerjm The "@" in that code tells xpath that "id" is an attribute. RTFM
  2. 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.
  3. 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?
  4. Then read the reply - I have told you how. Yes you are, you just don't realize it.
  5. 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%
  6. Change the ["gif", "jpg", "png"] to array("gif", "jpg", "png")
  7. 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.
  8. 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
  9. Do you think $results should be $result, perhaps?
  10. 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>';
  11. 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 | +---------------------+------+-------+---------+---------+-----------+
  12. Yes! approx 30 emails from the site sitting in my inbox.
  13. Are notification emails going to be brought back too?
  14. 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
  15. That's the puzzling thing - according to the last four lines in the code (initial post) they are quoted
  16. 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.
  17. try echo '<pre>' . print_r($row, true) . '</pre>'; That should show what indexes you do have in a $row array
  18. 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.
  19. 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
  20. 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
  21. You haven't executed the prepared statement
  22. If the user wants "All", leave that column out of the criteria.
  23. How does a teacher check which pupils are absent from a class? S/he has a register of the pupils that should be there. You are trying to count things that aren't there, so you need a "model" table containing a row for each model - your register. You then query SELECT i.status , m.model , COUNT(i.model) FROM model m LEFT JOIN club_inventory i ON m.model = i.model AND status="In-Stock" AND prod="Jets" GROUP BY m.model
  24. Your code is like walking into a room and asking "Will anyone who isn't here please raise their hand".
  25. try something like this $db = new mysqli(HOST,USERNAME,PASSWORD,'test'); $sql = "SELECT comment_id , username , post_id , content , IFNULL(parent_comment_id,0) , created FROM comment c INNER JOIN user u ON c.user_id = u.id ORDER BY post_id, created"; $comments = []; $res = $db->query($sql); while (list($cid,$user,$pid,$content,$parent,$created) = $res->fetch_row()) { $comments[$pid][$parent][$cid] = [ 'content' => $content, 'user' => $user, 'date' => $created ]; } // // recursive print function // function printReplies(&$comments, $parent, $level) { if (!isset($comments[$parent])) return; foreach ($comments[$parent] as $cid => $comdata) { $dval = date('F jS Y g:ia', strtotime($comdata['date'])); // print comment echo "<div class='comdiv lev$level'> <b>{$comdata['user']}</b><br>$dval<br> {$comdata['content']} </div>\n"; // print replies to the comment printReplies($comments, $cid, $level+1); } } ?> <!DOCTYPE html> <html> <head> <title>Sample sub-comments</title> <style type='text/css'> .comdiv { border: 1px solid gray; width: 400px; margin-top: 5px; padding: 10px; } .lev0 { margin-left: 50px; background-color: #cfc; } .lev1 { margin-left: 100px; background-color: #ccf; } .lev2 { margin-left: 150px; background-color: #ffc; } </style> </head> <body> <?php foreach ($comments as $post => $comms) { echo "<h3>Post $post</h3>"; printReplies($comms, 0, 0); } ?> </body> </html> results attached
×
×
  • 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.