Jump to content

Barand

Moderators
  • Posts

    24,607
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. Missing semicolon at end of line 5. You have it inside the string instead of after it.
  2. Give all the divs a class of "mydiv". Then in the <style> section change #mydiv { display: none; } to .mydiv { display: none; } then they all start off hidden.
  3. What has that response to do with my last question? i.e.
  4. I guessed that but your code shows no indication if any code that is buiding your links and divs from a query result. You've shown us that you put the row id in the onclick event call. Where do you put the same id in the div's id attribute?
  5. Where did $row suddenly spring from? Your code showed nothing like that.
  6. Each time I click the button it either shows or hides the div so I cannot reproduce your problem. Is your code different from mine?
  7. Same problem
  8. As basic as it gets... <!DOCTYPE html> <html lang="en"> <head> <title>Sessions &amp; Terms</title> <meta charset="utf-8"> <script type='text/javascript'> function showDiv() { let thediv = document.getElementById("mydiv") if (thediv.style.display == "block") { thediv.style.display = "none" } else { thediv.style.display = "block" } } </script> <style type='text/css'> #mydiv { display: none; } </style> </head> <body> <button onclick='showDiv()'>Show Div</button> <br> <div id='mydiv'> <h1>Hello, world</h1> </div> </body> </html>
  9. As the message tells you, you can't call session_start() after you have sent data to the browser. You are sending output on line 10 apparently. For example, the gap between ?> and the following <?php will result in a couple of newlines being sent.
  10. $arr = [ 1, 2, 3, 1, 4, 5, 2, 6, ]; $arr2 = array_unique($arr); // to force a unique set of values $arr3 = array_count_values($arr); // to verify they are all unique
  11. 2 new things. fetchAll() is a PDO method.
  12. So there is! $result = $db->query("select sku_numbers from table"); $skus = $result->fetchAll(PDO::FETCH_COLUMN); Thanks @mac_gyver - one keeps on learning.
  13. $result = $db->query("select sku_numbers from table"); $rows = $result->fetchAll(); $sku_array = array_column($rows, 'sku_numbers'); Probably faster using the inbuilt functions.
  14. Not according to the first post...
  15. Right. The links need to be created on your web page, SQL is confined to the DB server. This query fetches the chosen page of results after a link is clicked..
  16. No problem. Make that query a subquery of your query doing the pagination so that you paginate the results of the query. For example SELECT rank , name , donated , received FROM ( -- THIS IS THE QUERY TO DO THE RANKING - NOW A SUBQUERY SELECT id , name , @seq := @seq + 1 as seq , @rank := CASE WHEN total_received = @prevr THEN CASE WHEN total_donated = @prevd THEN @rank ELSE @seq END ELSE @seq END as rank , @prevr := total_received as received , @prevd := total_donated as donated FROM ( SELECT id , name , total_donated , total_received FROM donation WHERE total_participant = 1 ORDER BY total_received DESC, total_donated ASC LIMIT 18446744073709551615 ) ordered JOIN ( SELECT @rank := 0, @seq := 0, @prevd := 0, @prevr := 0 ) init ) ranked -- END OF RANKING SUBQUERY ORDER BY rank LIMIT ?, ? "; Running that query with LIMIT 0, 4, then LIMIT 4,4 gave 2 pages... Page 1 +------+---------+---------+----------+ | rank | name | donated | received | +------+---------+---------+----------+ | 1 | Dasher | 250 | 500 | | 2 | Cupid | 370 | 400 | | 2 | Prancer | 370 | 400 | | 4 | Comet | 370 | 380 | +------+---------+---------+----------+ Page 2 +------+---------+---------+----------+ | rank | name | donated | received | +------+---------+---------+----------+ | 5 | Dancer | 510 | 200 | | 6 | Vixen | 200 | 100 | | 7 | Donner | 510 | 100 | +------+---------+---------+----------+
  17. UPDATE users SET status = 'Offline now' WHERE status = 'Active now' ;
  18. The purpose of the subquery is to sort the data into the required order (ORDER BY total_received DESC, total_donated ASC) before applying the rankings. MariaDB ignores ORDER BY in subqueries. The way round it is the large LIMIT value to force it to write to a temporary table on disc.
  19. In that case you need to uncomment the line in the query where it says "required by mariaDB users"
  20. Are you using MySql or MariaDB?
  21. It's SQL (Structured Query Language - the language that all database queries use) Neither PDO nor mysqli - it will work with either. The '@' prefix is used for user variables. In this case I use those @seq, @rank, @prevr and @prevd for the sequence count, rank, previous record's received value and previous record's donation value so that I can store the values in one record and refer to them in the next one. The := is the assignent operator for user variables in SQL.
  22. @kicken Nice. I'll have to have another go at installing v8.0 as I mentioned, that was the quick and dirty way. IMO a better way (pre v8.0) is as below. In my tests, this method was typically around 6x faster on that small dataset. Savings would be greater with larger sets. Quick n dirty : 0.0034 seconds Long n clean : 0.0005 seconds SQL SELECT name , @seq := @seq + 1 as seq , @rank := CASE WHEN total_received = @prevr THEN CASE WHEN total_donated = @prevd THEN @rank ELSE @seq END ELSE @seq END as rank , @prevr := total_received as received , @prevd := total_donated as donated FROM ( SELECT name , total_donated , total_received FROM donation WHERE total_participant = 1 ORDER BY total_received DESC, total_donated ASC -- LIMIT 18446744073709551615 --(required by mariaDB users only - bug workaraound) ) ordered JOIN ( SELECT @rank := 0, @seq := 0, @prevd := 0, @prevr := 0 ) init ; Sample results +---------+------+------+----------+----------+ | name | seq | rank | received | donated | +---------+------+------+----------+----------+ | Dasher | 1 | 1 | 500 | 250 | | Cupid | 2 | 2 | 400 | 370 | | Prancer | 3 | 2 | 400 | 370 | | Comet | 4 | 4 | 380 | 370 | | Dancer | 5 | 5 | 200 | 510 | | Vixen | 6 | 6 | 100 | 200 | | Donner | 7 | 7 | 100 | 510 | +---------+------+------+----------+----------+
  23. Perhaps SELECT * FROM donation; +----+---------+---------------+----------------+-------------------+ | id | name | total_donated | total_received | total_participant | +----+---------+---------------+----------------+-------------------+ | 1 | Comet | 370 | 380 | 1 | | 2 | Cupid | 370 | 400 | 1 | | 3 | Donner | 510 | 100 | 1 | | 4 | Blitzen | 480 | 350 | 0 | | 5 | Dancer | 510 | 200 | 1 | | 6 | Prancer | 370 | 400 | 1 | | 7 | Dasher | 250 | 500 | 1 | | 8 | Vixen | 200 | 100 | 1 | +----+---------+---------------+----------------+-------------------+ SELECT name , total_received , total_donated , ( SELECT COUNT(*)+1 FROM donation rd2 WHERE ( rd2.total_received > rd1.total_received OR ( rd2.total_received = rd1.total_received AND rd2.total_donated < rd1.total_donated ) ) AND total_participant = 1 ) AS rank FROM donation rd1 WHERE total_participant = 1 ORDER BY total_received DESC, total_donated ASC +---------+----------------+---------------+------+ | name | total_received | total_donated | rank | +---------+----------------+---------------+------+ | Dasher | 500 | 250 | 1 | | Cupid | 400 | 370 | 2 | | Prancer | 400 | 370 | 2 | | Comet | 380 | 370 | 4 | | Dancer | 200 | 510 | 5 | | Vixen | 100 | 200 | 6 | | Donner | 100 | 510 | 7 | +---------+----------------+---------------+------+
  24. They are table aliases. Easier to write rd2.total_received than random_donation_clash2.total_received
×
×
  • 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.