Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation since 11/22/2020 in all areas

  1. Meanwhile, here's an alternative solution to my previous one, this one without the SQL variables. SELECT SUM(CASE WHEN DATE(datein) > DATE(dateout) THEN DATEDIFF(datein, dateout) - 1 ELSE 0 END ) as tot_absent FROM ( SELECT a.dateout , MIN(b.datein) as datein FROM ajoo_login a LEFT JOIN ajoo_login b ON a.dateout < b.datein GROUP BY a.dateout ) logins; +------------+ | tot_absent | +------------+ | 327 | +------------+
    2 points
  2. OK, I loaded your data into a test table INSERT INTO ajoo_login (datein, dateout) VALUES ('2019-03-30 17:05:24', '2019-03-30 17:09:47'), ('2019-04-01 15:13:32', '2019-04-01 15:19:46'), ('2019-04-04 23:37:21', '2019-04-04 23:50:51'), ('2019-04-18 15:28:35', '2019-04-18 15:33:10'), ('2019-04-23 16:35:20', '2019-04-23 16:42:35'), ('2019-04-24 12:03:07', '2019-04-24 12:10:28'), ('2019-05-01 08:05:48', '2019-05-01 08:20:28'), ('2019-05-08 18:04:04', '2019-05-08 18:14:57'), ('2019-05-09 08:18:15', '2019-05-09 08:29:38'), ('2019-06-18 12:49:01', '2019-06-18 13:10:15'), ('2019-09-05 17:17:33', '20
    2 points
  3. NOTE: both instances of $db->query(..) in the above post should be $db->prepare(..)
    2 points
  4. Because of the JOIN, it is initialized before it is used. As an alternative to the join you could have two queries ... SELECT @prevout := NULL; -- initialize @prevout SELECT SUM(diff) AS tot_absent FROM ( SELECT CASE WHEN DATE(datein) > DATE(@prevout) THEN DATEDIFF(datein, @prevout) - 1 ELSE 0 END AS diff , datein , @prevout := dateout AS dateout -- store dateout in @prevout FROM ajoo_login ) logins; @vars are just like va
    1 point
  5. Where did that suddenly spring from? There's no mention in your original post. Don't keep us in the dark and still expect help.
    1 point
  6. My version would be to JOIN the table to itself once or twice in order to pair up consecutive records, then DATEDIFF()-1 the end of the first with the start of the second, then SUM the results.
    1 point
  7. Well, this would be one of those times. You can't do simple math like $now - $last with the value returned by microtime(). You need to use microtime(true) for that. For example: <?php $last = microtime(); sleep(5); $now = microtime(); $diff = $now - $last; printf("%0.4f seconds have passed", $diff); One might expect since the script sleeps for 5 seconds to get a result like 5.xxxx seconds have passed but what you actually get is: Notice: A non well formed numeric value encountered in W:\expired.php on line 7 Call Stack: 0.0002 391984 1. {main}() W:\expired.ph
    1 point
  8. plogsID=plogsID will always be true. SELECT * FROM blogs WHERE blogsStatus=1 AND blogsID=blogsID You have several options. See https://www.php.net/manual/en/pdo.prepare.php, but to get you started... $stmt = $db->query('SELECT * FROM blogs WHERE blogsStatus=1 AND blogsID=:blogsID'); $stmt->execute(['blogsID' => $blogsID]); $result = $stmt->fetch(PDO::FETCH_ASSOC); $stmt = $db->query('SELECT * FROM blogs WHERE blogsStatus=1 AND blogsID=?'); $stmt->execute([$blogsID]); $result = $stmt->fetch(PDO::FETCH_ASSOC); Or you can use use bindParam() or bindVal
    1 point
  9. You were close with your original method but it needed a couple of tweaks while fetch { if $type != $t { if $t != '' output </optgroup> // only close previous group if there was one output <optgroup> $t = $type end if output <option> end while output </optgroup> // close final group
    1 point
  10. I have an inflateable baseball bat which I often use on such occasions.
    1 point
  11. What if you echo the query string to examine the syntax? echo "SELECT * FROM MK_migration_details WHERE mig_bid='".$_SESSION['bid']."'";
    1 point
  12. Telling us what the problem is goes a long way towards getting it resolved.
    1 point
This leaderboard is set to New York/GMT-05:00
  • Newsletter

    Want to keep up to date with all our latest news and information?
    Sign Up
×
×
  • 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.