Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation since 10/29/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. try $arr = array("test", "test", "hello", "test", "world", "world", "world", "hello", "test"); $prev = ''; $results = []; $j = 0; foreach ($arr as $i => $v) { if ($v != $prev) { $j = $i; $results[$j] = 1; $prev = $v; } else { $results[$j]++; } } foreach ($results as $k => $v) { echo "$arr[$k] : $v <br>"; } Result: test : 2 hello : 1 test : 1 world : 3 hello : 1 test : 1
    1 point
  12. if array == array[i-1] then you have adjacent duplicates
    1 point
  13. The link to the manual has examples.
    1 point
  14. That's it. "-p X:Y" maps the host's X to the container's Y. Make sure the container (and Apache) is running, and that you're browsing to localhost:8080. You should definitely get a connection, even if something else doesn't work.
    1 point
  15. What if you echo the query string to examine the syntax? echo "SELECT * FROM MK_migration_details WHERE mig_bid='".$_SESSION['bid']."'";
    1 point
  16. Personally I wouldn't start off learning PDO by doing try-catch statements as in my opinion will cause more confusion than it is worth. Simply have error reporting turned on to catch the errors. I personally don't like writing foreach statements that way, I would write it something like the following: <?php foreach ($result as $text) { echo '<blockquote>'; echo '<p>' . htmlspecialchars($text['joketext']) . '</p>'; echo '</blockquote>'; } ?> as for the pdo I would do something like the following: $db_options = array( /* i
    1 point
  17. Telling us what the problem is goes a long way towards getting it resolved.
    1 point
  18. Just a thought, but did you ever consider using sprintf() instead of echo()? sprintf( '<li><a href="%s" title="%s"><i class="%s"></i> %s</a></li>' , $row['url'] , $row['title'] , $row['icon'] , $row['header'] ); Regards, Phill W.
    1 point
  19. You can't store an array in a database as a single column. I already suggested what to do. Alternatively you can store the array in a join table where each item is a column.
    1 point
  20. If you have PHPAdmin with admin rights then you need to check GRANTs for user 'apache'. That is likely the crux of your problem.
    1 point
  21. The user privileges defined in the mysql database for whichever username you are connecting with.
    1 point
  22. Because you're not quoting your label properly. You're going to be generating a function call that looks like myfunction(8, The world's best cider); That's invalid Javascript, your label needs to be inserted as a valid string literal so that you'd end up with a call that looks like: myfunction(8, 'The world\'s best cider'); Such a thing can be done, but it's pain to do and this whole approach is the wrong way to accomplish this anyway so you shouldn't bother trying to figure out how to quote your string. There are varying way's to do this more correctly, but the way that wo
    1 point
  23. I'm not familiar with the ESP32 in particular but usually these micro-controller products are no where near capable of running an SQL database locally. For the ones that have networking capabilities, you can usually get some sort of TCP/IP connection going either via a minimal HTTP server or custom socket setup. It looks like that's what the whole MQTT thing is so that sounds like a good option. For the ones without networking capabilities you'd generally hook them up to a computer via a serial connection and connect to it that way. This is what I've usually done for my occasional
    1 point
  24. This is just a matter of two separate levels of escape sequence processing that you need to wrap your mind around, which can be difficult at times. When you're setting a string in PHP first you have PHP's escape sequence processing. PCRE then has it's own level of processing that is done on the value that was passed to the function. For example, if you wanted to use \0 in a replacement literally rather than have it interpreted as a back reference you have to pass the string '\\0' as your replacement. If you're defining value in your PHP source as a string then you need to escape thos
    1 point
  25. Is this what you want to achieve Receipts Batch | a | b | c | d | Date | 2020-01-01 | 2020-01-02 | 2020-01-03 | 2020-01-04 | Qty | 15 | 10 | 23 | 30 | ------------------------+--------------+--------------+--------------+--------------+ Issues | | | | | | | | | | 2020-01-01 10 | 10
    1 point
  26. Surprisingly, that tutorial got it pretty right. It could use a hand full of small improvements but overall they got it right.
    1 point
  27. Yes. Session start must be called on each page on which you want to share data.
    1 point
  28. var jsonObj = request.result; This sets jsonObj to undefined because XMLHttpRequest doesn't have a result property. You need to read and parse the responseText property. XMLHttpRequest is an older standard. You might also want to look at the more modern fetch() API instead.
    1 point
  29. Just to make sure, for benanamen's suggestion, you should replace the following line: if(isset($_POST["submit"])) With the line below. Note that I removed the curly / smart quotes around POST. if($_SERVER['REQUEST_METHOD'] == 'POST') I would also add some sort of debug code to see if the if test is working. For example, if($_SERVER['REQUEST_METHOD'] == 'POST') { echo '<br>form submission detected'; Does the script display "form submission detected" after submitting the form? Also, if the script still doesn't work as you expect, please post your most recent code.
    1 point
  30. You have made a classic mistake of depending on the name of a button to be submitted for your code to work instead of checking the POST Request Method. Since you didn't name your submit button, the code does not do anything. The fix is NOT to add a name to the button, but to instead check the REQUEST METHOD instead. Depending on the name of a button to be submitted will completely fail in certain cases. if($_SERVER['REQUEST_METHOD'] == ‘POST’){ // Do stuff } Your error checks will also fail. You need to trim the entire POST array and then check for empty. Do not create v
    1 point
  31. I see the session start but I don't see where you set any $_SESSION variables. Where is the code that outputs the error you say is not showing up?
    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.