Jump to content

Barand

Moderators
  • Posts

    24,356
  • Joined

  • Last visited

  • Days Won

    798

Posts posted by Barand

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

     

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

     

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

     

  4. 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"

     

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

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

  7. Yes.

    Here's a simplified version of your application as an example

    FORM CODE

    <?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},
                function(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></tr>\n"
                    })
                    $("#playlist").html(list)
                },
                "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

    <?php
    session_start();
    
    if ($_SERVER['REQUEST_METHOD']=='POST') {
        $voice_id = $_POST['voice_id'] ?? 0;
        $voice_name = $_POST['voice_name'] ?? '';
        
        if ($voice_id && $voice_name) {
            $_SESSION['playlist'][$voice_id] = $voice_name;
            exit(json_encode($_SESSION['playlist'])) ;
        }
    }
    exit("ERROR")  ; 
    ?>

     

    • Great Answer 1
  8. my_cart.php will not display anything to the user.

    When you use ajax, all output is sent back to the calling ajax function in the ajax response. In your case it will be in the "data" argument

    success: function(data)                    // <-- output from "my_cart.php" is in "data"
        {
            console.log(data);               
            // console.log('success',data);
            
        }

    Note that these are processed one at a time as you click each button. If you want to list multiple items then you would add them to a list on the calling page, not in my_cart.php. Alternatively you could store them with my_cart.php (maybe in a "playlist" table in a database) and list them in another page.

    If the list needs to be persistent, store them.

  9. Yet, there it is in the manual.

    The php.net function search is crap in this respect. You have to search first for the "mysqli-result" class to get to the methods

    image.png.1f1ea2908dd285843edbf0579e60bc68.png

    • fetch() is mysqli-statement method
    • fetch_assoc() is a mysqli-result method.

    That's the main problem with mysqli - there are two different sets of methods to process the results depending on whether you used query() or prepare().

  10. On closer examination, your button script is expecting HTML elements with ids of "voice_id" and "voice_name" with values.

    1. You don't have any such elements
    2. ids must be unique and you will have several buttons and voice_ids.

    i would add hidden fields to hold the names and ids

    <input type="hidden" name="voice_id" value="{$row[voice_id]}"   class="voice_id" data-id="{$row[voice_id]}">
                        <input type="hidden" name="voice_name" value="{$row[voice_name]}"   class="voice_name" data-id="{$row[voice_id]}">
                        <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="{$row[voice_id]}">Add to PlayList </button>

    Note the hidden fields and button all share the same data-id values.

    The use those data-id values to get the voces associated with buttons

    $('.btn').on('click',function() {
            var vid = $(this).data("id")
            var voice_id     = $(".voice_id[data-id="+vid+"]").val();
            var voice_name  = $(".voice_name[data-id="+vid+"]").val();
    
            $.ajax({
                type      : "POST",
                url       : "my_cart.php",
                datatype : "text",
                data     : {voice_id: voice_id, voice_name: voice_name },
                success: function(data)
                {
                    console.log(data);
                    // console.log('success',data);
                    
                }
            });
        });

     

×
×
  • 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.