Jump to content

Barand

Moderators
  • Content Count

    19,376
  • Joined

  • Last visited

  • Days Won

    381

Everything posted by Barand

  1. Which is which? Can you provide your table structures and, perhaps, some sample data. (SQL dump maybe)
  2. I have modofied my original example to include "Delete" buttons in the playlist. At some point you will need to commit the playlist stored in the session to permanant storage. Selection page... <?php // // FOR DEBUG PURPOSES ONLY - LIST CONTENTS OF SESSION PLAYLIST // session_start(); if (isset($_SESSION['playlist'])) { echo '<pre>', print_r($_SESSION['playlist'], 1), '</pre>'; echo "</hr><br>\n"; } ?> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $().ready( function() { $(".btn").click( function() { var vid = $(this).data("id"); var vname = $(this).data("name"); $.post( "my_cart.php", { "voice_id" : vid, "voice_name" : vname, "action" : "Add" }, function(resp) { outputPlaylist(resp) }, "JSON" ) }) function outputPlaylist(resp) { var list = "<tr><td><b>ID</b></td><td><b>Title</b></td></tr>\n"; $.each(resp, function(k, v) { list = list + "<tr><td>" + k + "</td><td>" + v + "</td>" list = list + "<td><button class='delbtn' data-id='"+ k +"'>Delete</button></td></tr>\n" // add "Delete" button to each playlist item }) $("#playlist").html(list) // define action for new delbtn's $(".delbtn").click( function() { var vid = $(this).data("id"); $.post( "my_cart.php", { "voice_id" : vid, "action" : "Delete"}, function(resp) { outputPlaylist(resp) }, "JSON" ) }) } }) </script> </head> <body> Song 1 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="1" data-name="song-1.mp3">Add to PlayList </button> <br> Song 2 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="2" data-name="song-2.mp3">Add to PlayList </button> <br> Song 3 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="3" data-name="song-3.mp3">Add to PlayList </button> <br> Song 4 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="4" data-name="song-4.mp3">Add to PlayList </button> <br> Song 5 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="5" data-name="song-5.mp3">Add to PlayList </button> <br> Song 6 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="6" data-name="song-6.mp3">Add to PlayList </button> <br> <br> <h2>Playlist</h2> <table style="width:600px" id="playlist"> </table> </body> </html> my_cart.php (handles ajax requests)... <?php session_start(); if ($_SERVER['REQUEST_METHOD']=='POST') { $voice_id = $_POST['voice_id'] ?? 0; $action = $_POST['action'] ?? ''; if ($action == 'Delete') { // we are deleting the item from the session array if ($voice_id) { unset($_SESSION['playlist'][$voice_id]); exit(json_encode($_SESSION['playlist'])) ; } } elseif ($action == 'Add') { // we are adding the item $voice_name = $_POST['voice_name'] ?? ''; if ($voice_id && $voice_name) { $_SESSION['playlist'][$voice_id] = $voice_name; exit(json_encode($_SESSION['playlist'])) ; } } else { exit("ERROR") ; } } exit("ERROR") ; ?>
  3. Therein lies your problem. The parent id is $child['parentid'] since $child is the array, not $row. (When you get that error message on the first iteration, $row contains "1")
  4. You need to be aware of what your variables contain. It would seem that $row is a string and not an array. What does this output... echo '<pre>', print_r($child, 1), '</pre>';
  5. You are referencing the variable $question inside your function $question must be defined inside the function or passed to the function as an argument,
  6. You can't pass arguments by reference in the function call. The "by reference" should be defined in the function definition EG // define function function my_func(&$chr) { // do something to $chr ++$chr; } // call function $x = "A"; echo $x; // A my_func($x); echo $x; // B (I am surprised that that 5.3 didn't have an adverse reaction to your code. I thought that restriction had been around longer than that)
  7. Barand

    Dark Theme

    Well done, that looks much better. The "patchwork" effect has gone now and there is a subtle but distinct grouping of the elements. Icons next to board titles are also clearer.
  8. Barand

    Dark Theme

    The rectangle around the latest post on each board
  9. Barand

    Dark Theme

    "Home" page looks a mess with element backgrounds not quite matching parent background. Blobs and stars next to topics are indistinct
  10. Perhaps something like $links['company_website'] = get_the_company_website(); $links['company_twitter'] = get_the_company_twitter(); $links['company_facebook'] = get_post_meta( get_the_ID(), '_facebook_link', true ); foreach (array_filter($links) as $cls = $link) { // output link }
  11. or test = $(".sw_ui").val(); alert(test); isnum = /^\d+$/.test(test); alert(isnum);
  12. What value is that JS supposed to be testing? I see nothing with a class = "test"
  13. This worked for me once I had escaped the single quotes inside your "onclick" $data = [ 'pagecontent' => '<p>We just need to ask you a few questions so we can get you the right answer</p><h2>What is your age?</h2> <form> <select id="verifyage" name="verifyage" class="dropdown-fields" required> <option value="0">--Select your age--</option> <option value="3A1">Under 16</option> <option value="3A2">16 Or 17</option> <option value="3A3">18 Or Over</option> </select> <input type="submit" name="btnsubmit" id="btnsubmit" class="button" onClick="gotonextpage($(\'#verifyage option:selected\').val());"> <form> <p> </p>' ]; $j = json_encode($data);
  14. That tells me absolutely nothing about your data structure. How do expect help with responses like that when we ask for more information? A table structure such as this one would solve the problems in both your topics +----------------+ +-------------------+ +---------------------+ | customer | | role | | shipping_method | +----------------+ +-------------------+ +---------------------+ | cust_id | +-------| role_id |--+ +---| method_id | | cust_name | | | role_name | | | | method_description | | role_id |>------+ | PST_payable | | | | tracking_available | | ... | | GST_payable | | | +---------------------+ +----------------+ +-------------------+ | | | | | +---------------------+ | | | role_method | | | +---------------------+ | | | role_method_id | | +--<| role_id | | | method_id |>-+ +---------------------+ If, for example, your table data looks like this customer shipping_method +---------+------------+---------+ +-----------+--------------------+--------------------+ | cust_id | cust_name | role_id | | method_id | method_description | tracking_available | +---------+------------+---------+ +-----------+--------------------+--------------------+ | 1 | Customer A | 1 | | 1 | Carrier pigeon | 0 | | 2 | Customer B | 2 | | 2 | Pony Express | 0 | | 3 | Customer C | 3 | | 3 | Drone | 1 | | 4 | Customer D | 17 | | 4 | Silvia Standard | 1 | | 5 | Customer E | 15 | | 5 | Silvia Premium | 1 | | 6 | Customer F | 11 | +-----------+--------------------+--------------------+ | 7 | Customer G | 18 | | 8 | Customer H | 17 | | 9 | Customer I | 4 | role_method | 10 | Customer J | 10 | +----------------+---------+-----------+ +---------+------------+---------+ | role_method_id | role_id | method_id | +----------------+---------+-----------+ | 1 | 1 | 1 | role | 2 | 1 | 2 | +---------+-------------------------------------+-------------+-------------+ | 3 | 1 | 3 | | role_id | role_name | pst_payable | gst_payable | | 4 | 2 | 1 | +---------+-------------------------------------+-------------+-------------+ | 5 | 2 | 2 | | 1 | Customer | 1 | 1 | | 6 | 2 | 3 | | 2 | Customer pst exempt | 0 | 1 | | 7 | 3 | 1 | | 3 | Customer tax exempt | 0 | 0 | | 8 | 3 | 2 | | 4 | Wholesale Customer | 1 | 1 | | 9 | 3 | 3 | | 5 | Wholesale Silvia Silver | 1 | 1 | | 10 | 4 | 1 | | 6 | Wholesale Silvia Gold | 1 | 1 | | 11 | 4 | 2 | | 7 | Wholesale Silvia Premium | 1 | 1 | | 12 | 4 | 3 | | 8 | Wholesale Silvia Union | 1 | 1 | | 15 | 5 | 1 | | 9 | Wholesale | 0 | 1 | | 16 | 5 | 2 | | 10 | Wholesale Silvia Silver pst exempt | 0 | 1 | | 17 | 5 | 3 | | 11 | Wholesale Silvia Gold pst exempt | 0 | 1 | | 18 | 5 | 4 | | 12 | Wholesale Silvia Premium pst exempt | 0 | 1 | | 19 | 5 | 5 | | 13 | Wholesale Silvia Union pst exempt | 0 | 1 | | 20 | 6 | 1 | | 14 | Wholesale tax exempt | 0 | 0 | : : : | 15 | Wholesale Silvia Silver tax exempt | 0 | 0 | : : : | 16 | Wholesale Silvia Gold tax exempt | 0 | 0 | : : : | 17 | Wholesale Silvia Premium tax exempt | 0 | 0 | | 80 | 18 | 1 | | 18 | Wholesale Silvia Union tax exempt | 0 | 0 | | 81 | 18 | 2 | +---------+-------------------------------------+-------------+-------------+ | 82 | 18 | 3 | | 83 | 18 | 4 | | 84 | 18 | 5 | +----------------+---------+-----------+ ... then a single query can get all you need for a customer. (This shows data for all customers for comparison) SELECT cust_id , cust_name , role_id , role_name , pst_payable , gst_payable , GROUP_CONCAT(method_description ORDER BY method_id SEPARATOR ' / ') as shipping_methods FROM customer c JOIN role r USING (role_id) JOIN role_method rm USING (role_id) JOIN shipping_method sm USING (method_id) GROUP BY c.cust_id; +---------+------------+---------+-------------------------------------+-------------+-------------+--------------------------------------------------------------------------+ | cust_id | cust_name | role_id | role_name | pst_payable | gst_payable | shipping_methods | +---------+------------+---------+-------------------------------------+-------------+-------------+--------------------------------------------------------------------------+ | 1 | Customer A | 1 | Customer | 1 | 1 | Carrier pigeon / Pony Express / Drone | | 2 | Customer B | 2 | Customer pst exempt | 0 | 1 | Carrier pigeon / Pony Express / Drone | | 3 | Customer C | 3 | Customer tax exempt | 0 | 0 | Carrier pigeon / Pony Express / Drone | | 4 | Customer D | 17 | Wholesale Silvia Premium tax exempt | 0 | 0 | Carrier pigeon / Pony Express / Drone / Silvia Standard / Silvia Premium | | 5 | Customer E | 15 | Wholesale Silvia Silver tax exempt | 0 | 0 | Carrier pigeon / Pony Express / Drone / Silvia Standard / Silvia Premium | | 6 | Customer F | 11 | Wholesale Silvia Gold pst exempt | 0 | 1 | Carrier pigeon / Pony Express / Drone / Silvia Standard / Silvia Premium | | 7 | Customer G | 18 | Wholesale Silvia Union tax exempt | 0 | 0 | Carrier pigeon / Pony Express / Drone / Silvia Standard / Silvia Premium | | 8 | Customer H | 17 | Wholesale Silvia Premium tax exempt | 0 | 0 | Carrier pigeon / Pony Express / Drone / Silvia Standard / Silvia Premium | | 9 | Customer I | 4 | Wholesale Customer | 1 | 1 | Carrier pigeon / Pony Express / Drone | | 10 | Customer J | 10 | Wholesale Silvia Silver pst exempt | 0 | 1 | Carrier pigeon / Pony Express / Drone / Silvia Standard / Silvia Premium | +---------+------------+---------+-------------------------------------+-------------+-------------+--------------------------------------------------------------------------+
  15. The last topic you posted had a similar set of convoluted arrays for tax rates. Now you are trying to handle shipping methods by the same method. Why doesn't your database reflect these rates and methods for each customer role so you can easily query for them. Whaat is your data structure?
  16. Didn't I answer this already a few days ago?
  17. $numbers = array(1,3,7,8,10,13); $max = max(array_filter($numbers, function($v) { return $v%2==0; })) ;
  18. A category would be checked if its id is in the array of category ids from the form input.
  19. OK, guessing this is a "lottery". Use array_intersect() to find matching numbers $results = [ 4, 36, 44, 55, 57 ]; $user = [ 3, 21, 44, 45, 55 ]; $matching = array_intersect($results, $user); Check echo '<pre>', print_r($matching, 1), '</pre>'; Array ( [2] => 44 [3] => 55 )
  20. If your calc sheet looks like this then File/Save As... select CSV as the file type and save should give this Date,Title,Text 01/01/2019,Lukas:16:19,"Es war ein reicher Mann, der kleidete sich in Purpur und kostbares Leinen" 01/02/2019,Kolosser:3:13,Ertrage einer den andern und vergebt euch untereinander 01/03/2019,1.Petrus:5:10,"Der Gott aller Gnade, der euch berufen"
  21. I haven't studied you code in detail but, in general when dealing with a mix of AND and OR, use parentheses to define the desired logic. "AND" and "OR" usualy have different binding values. EG : A AND B OR C Is that A AND (B OR C) or is it (A AND B) OR C (The latter would be the default, "AND" having a greater binding)
  22. We are not going to do your assignment for you but, if you show us what you have so far, we can point you in the right direction.
  23. consider <?php $dt1 = new DateTime(); $dt2 = new DateTime('2019-12-31'); echo $dt1->diff($dt2)->d . '<br>'; //--> 24 echo $dt1->diff($dt2)->days . '<br>'; //--> 177 ?> "d" gives days as in 6 months 24 days. "days" gives the total number of days
  24. Neither do we without knowing your table structure. Your select query syntax is completely screwed. You need to use a WHERE clause to conditionally select data. You also need to check the PHP manual for examples of to process your queries. (There is a SQL tutorials link in my sig) The mysql_ functions you are using no longer exist in PHP and were deprecated years ago. You should now be using the mysqli (improved) or PDO. (PDO is highly recommended over mysqli)
×
×
  • 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.