-
Posts
24,356 -
Joined
-
Last visited
-
Days Won
798
Posts posted by Barand
-
-
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 | +---------+------------+---------+-------------------------------------+-------------+-------------+--------------------------------------------------------------------------+
-
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?
-
Didn't I answer this already a few days ago?
- 1
-
$numbers = array(1,3,7,8,10,13); $max = max(array_filter($numbers, function($v) { return $v%2==0; })) ;
- 2
-
A category would be checked if its id is in the array of category ids from the form input.
-
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 )
-
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"
-
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)
-
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.
-
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
- 1
-
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)
-
Why all those if() statements?
- startValue = (pageValue - 1) * 50 + 1
- endValue = startValue + 49 (or pageValue * 50)
-
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") ; ?>
- 1
-
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.
-
8 hours ago, Chrisj said:
does this line have an extra ' in it, before the last " ?
echo "<meta name='robots' content='noindex'>'"; ^
Yes, it does. I can see it quite clearly (indicated by ^ ).
But it shouldn't have.
-
Use the developer tools in your browser (network tab) and check the ajax message and response.
Have you changed the html in your form so you now have voice_id and voice_name values?
-
According to the XML provided, assigned staff only have a id and name. Where are the other data coming from?
<Assigned> <Staff> <ID>610781</ID> <Name>Staff 1</Name> </Staff>
-
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
- 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().
-
53 minutes ago, ginerjm said:
PS - My php manual does not show this function in use - mysqli_fetch_array
-
Given the error message, my money's on the line that contains "mysqli_fetch_array()"
-
When you say "midnight US", to which of your six timezones do you allude?
It could mean any time between GMT 04:00 and GMT 10:00, (or, perhaps, you just mean "mañana" ?)
-
Then the chances are that your query failed and returned "false". See what mysqli_error() tells you.
-
On further thought you could forget my hidden inputs and just put the two values in the button as "data-id" and "data-name".
Then, in the click function
var voice_id = $(this).data("id") var voice_name = $(this).data("name")
- 1
-
On closer examination, your button script is expecting HTML elements with ids of "voice_id" and "voice_name" with values.
- You don't have any such elements
- 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); } }); });
PDO Output to JSON
in PHP Coding Help
Posted
This worked for me once I had escaped the single quotes inside your "onclick"