Jump to content

Barand

Moderators
  • Content Count

    21,140
  • Joined

  • Last visited

  • Days Won

    518

Barand last won the day on November 25

Barand had the most liked content!

Community Reputation

1,591 Excellent

7 Followers

About Barand

Profile Information

Recent Profile Visitors

65,112 profile views
  1. As I have no idea what the query was that produced those results, or what the input data to the query was, what is it you expect?
  2. Introducing your "studentlogin" column to the data ... +----+---------------------+---------------------+--------------+ | id | datein | dateout | studentlogin | +----+---------------------+---------------------+--------------+ | 1 | 2019-03-30 17:05:24 | 2019-03-30 17:09:47 | mina1111 | | 2 | 2019-04-01 15:13:32 | 2019-04-01 15:19:46 | abcd1234 | | 3 | 2019-04-04 23:37:21 | 2019-04-04 23:50:51 | xyz12345 | | 4 | 2019-04-18 15:28:35 | 2019-04-18 15:33:10 | mina1111 | | 5 | 2019-04-23 16:35:20 | 2019-04-23 16:42:35 | xyz12345 | | 6 | 2019-0
  3. 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
  4. The most common causes of that error are an opening { or " without a corresponding closing } or "
  5. 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 | +------------+
  6. 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.
  7. 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
  8. Have you considered RTFM?
  9. Yes. Make sure your data is ordered by date Use an @variable to store the record's date compare the date in record n with the date stored from record n-1 store the cumalative difference in a second @variable [edit] PS as it isn't possible to load your data into a test table from an image, that's all the help I'll give.
  10. NOTE: both instances of $db->query(..) in the above post should be $db->prepare(..)
  11. If the "ellipsis" operator is still a problem for you, that line can be rewritten as fwrite($fp, vsprintf('"%s","%s","%s","%s","%s","%s"'."\n", $v));
  12. If you read my code you would see I store my database connection in the variable $db. You are storing yours in $con. Therefore you need to use $con where I have used $db, such as in $db->prepare() 🙄
  13. In an attempt to remove confusion, here is a whole script. <?php include 'db_inc.php'; // use your own $db = myConnect('jimr'); // mysqli connection if ($_SERVER['REQUEST_METHOD']=='POST') { $stmt = $db->prepare("INSERT INTO player(uniform, nameFirst, nameLast) VALUES (?,?,?)"); $stmt->bind_param('sss', $uniform, $fname, $lname); foreach ($_POST['uniform'] as $k => $uniform) { $fname = $_POST['nameFirst'][$k]; $lname = $_POST['nameLast'][$k]; $stmt->execute(); } header("Location:#"); exit; } ?> <!DOC
  14. The three dots are significant, expanding the array into a comma separated list of values. They won't work with a PHP version before v5.6, but if that's case then you have more work to do bringing your PHP up to date (v7.4). Have you turned your error reporting and display on yet?
×
×
  • 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.