Jump to content

Barand

Moderators
  • Posts

    24,350
  • Joined

  • Last visited

  • Days Won

    796

Everything posted by Barand

  1. Why don't you acquire a UK postcode database with latitude and longitude information and base the prices/deliverability on distance (ranges)?
  2. In this excerpt from your code, all lines except the execute() are assigning values - you know how to assign in PHP.
  3. Right idea, but you can't just paste javascript code into php and expect it to work. The variable names and syntax are different.
  4. Just echo another <td>..</td> with the delete button html inside it.
  5. Was the comment on that line not a sufficient clue?
  6. In your loop above, when you output the key and the value, also output a delete button (just as I did in my example).
  7. Which is which? Can you provide your table structures and, perhaps, some sample data. (SQL dump maybe)
  8. 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") ; ?>
  9. 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")
  10. 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>';
  11. You are referencing the variable $question inside your function $question must be defined inside the function or passed to the function as an argument,
  12. 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)
  13. 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.
  14. The rectangle around the latest post on each board
  15. "Home" page looks a mess with element backgrounds not quite matching parent background. Blobs and stars next to topics are indistinct
  16. 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 }
  17. or test = $(".sw_ui").val(); alert(test); isnum = /^\d+$/.test(test); alert(isnum);
  18. What value is that JS supposed to be testing? I see nothing with a class = "test"
  19. 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);
  20. 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 | +---------+------------+---------+-------------------------------------+-------------+-------------+--------------------------------------------------------------------------+
  21. 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?
  22. Didn't I answer this already a few days ago?
  23. $numbers = array(1,3,7,8,10,13); $max = max(array_filter($numbers, function($v) { return $v%2==0; })) ;
  24. A category would be checked if its id is in the array of category ids from the form input.
×
×
  • 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.