Jump to content

Barand

Moderators
  • Content Count

    19,376
  • Joined

  • Last visited

  • Days Won

    381

Posts posted by Barand


  1. 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")  ; 
    ?>

     


  2. You are referencing the variable $question inside your function

    Quote

    function buildTree($child) {

        $branch = array();

        foreach ($child as $row) {

             $childresults = $question->read_children($row['parentid']); 

    $question must be defined inside the function or passed to the function as an argument,


  3. 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)


  4. 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);

     


  5. 21 hours ago, Lyse said:

    The data structure is MYSQL with tables.

    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 |
    +---------+------------+---------+-------------------------------------+-------------+-------------+--------------------------------------------------------------------------+

     


  6. 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
    )

     


  7. If your calc sheet looks like this

    image.png.6fa5cfcde9e72f7967799751d51dc79a.png

    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"

     


  8. 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)


  9. 14 minutes ago, the_toolman said:

    I also don’t know how to select them based on a time period of 3 days

    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.