Jump to content

gizmola

Administrators
  • Posts

    6,060
  • Joined

  • Last visited

  • Days Won

    153

Everything posted by gizmola

  1. Can we start with the fact that this is not a valid function: function price_format($price, $decimals = 2) { $CI =& get_instance(); $config = $CI->config->item('mcp'); $price = (float) $price; $formats = ["US" => ['.', ','], "EU" => [',', '.']]; $decimals = ($price >= 1 || $price == 0) ? $decimals : ($price < 0.000001 ? 8 : 6); return number_format($price, $decimals, $formats[$config['num_format']][0], $formats[$config['num_format']][1]); You're missing the closing curly bracket! You can lint your php files using command line php with php -l your_file_name.php, and it will show you if the file contains valid php or errors. Then you show more code, but you are never using price_format(). Instead you have: <?php echo $coinfeedde = number_format($coinfeed_current_price, 0, '.', '.'); ?>
  2. Your 3 arrays: $link = array_merge( array_fill_keys(['beF1LP','beN1LP'], 'https://www.site1.com'), array_fill_keys(['beF2LP','beN2LP'], 'https://www.site2.com'), array_fill_keys(['beF3LP','beN3LP'], 'https://www.site3.com') );
  3. Ok I'll play: $link = array_fill_keys(['beF1LP','beN1LP'], 'https://www.site.com');
  4. Some things in general that are unusual about your system and design: Usually a carton of items vs single items have different inventory numbers. The inventory system might have a BOM feature that reflects the Carton y contains some # of inventory item x. Thus inventory of item x would always be ((#y * quantity/per/carton) + quantity of x (loose/individual boxes)). You may or may not want to break open a carton in order to sell some# of individual item x, but that is a business rule. Otherwise, the items are separate for the point of inventory and sales. Usually a buyer is getting a price based on their status as a wholesale buyer vs. a direct-to-consumer. It's an odd design to pick from one or the other, because wholesale buyers are typically buying in quantity and getting a deal. I'm not sure what you are trying to achieve here, but often upsell can be achieved in a different manner, via messaging the customer to incent them to buy more to receive discounts of some sort. Without understand the functional design/use cases/user stories, it's not possible to suggest specific design solutions.
  5. Yes certainly. You use ajax. Ideally you have a rest api created that supports this. You would create your server api that takes the request parameters and returns the appropriate data. This is a generalized concept, but in your case, clearly the parameter is "buyertype" with either "retail" or "wholesale". Based on that, the rest api will return the price per item or price per carton, as well as the appropriate quantity available. You can use jquery to make these calls, or use the more modern technique of using fetch with ES6 promises. Be aware that jquery has a lot of wrappers around ajax that you can use, like jquery.get(), jquery.post() and jquery.getJSON(). Jquery Ajax Javascript Fetch My advice if you are doing new code that isn't heavily invested in jquery, is to use fetch(). In all cases return and work with JSON if you can. It's a much better match for javascript UI. It's ok, to use post or get methods to send the data, but return your results in JSON.
  6. For anyone who might stumble upon this question in the future: Data Transfer Object (DTO) For the purposes of this discussion, there are multiple Laravel Eloquent Models Article on DTO in a Symfony4 REST api Patterns of Enterprise Application Architecture by Martin Fowler
  7. First thing is that the code you pasted was syntactically incorrect. I fixed it and put your post into code tags, as well as indenting it correctly for the blocks. To be able to read and understand code, it needs to be indented properly. Concept: A php file can have both html and php blocks. A php block must start with <?php and end with ?>. If you put html markup in a php file, it will be seen as html markup, unless it is inside a php block. Do you understand how that is used in the file you presented? Are there any html blocks? Does the script drop in and out of php? Is there html intermixed with php? Do you understand what a function is/does? Barand helpfully posted links to some key php functions and language constructs used in this code. Did you review those? If you have done that, then if you can narrow down the code into specific sections of code you don't understand, people will be happy to help you with those. The journey of a thousand miles begins with a single step. Be curious and read and study the material we provided. Curiosity and focus are the keys to learning anything new, not just programming languages. Do you have a php environment setup where you can test the code? Being able to put in echo and print_r or var_dump statements are very helpful when studying code you don't understand fully.
  8. +1 for the party model, but I also want to point out that "superuser" is actually a security role, not an intrinsic attribute of a user.
  9. To set an attribute of an element you want something like this: el = document.getElementById("demo") el.setAttribute("value", (your_calculation))
  10. Changing something is fairly trivial, but as this hits close to home for us, what exactly is it that you are trying to do, and why?
  11. This is manipulation of the Invision(company that makes our forum, which was formerly known as IPBoard) framework for doing things with Invision community (the suite of stuff that includes what was once IPboard).
  12. How about just copying a .composer/Auth.json file into the docker container, and using composer inside the php container to do your composer install? A good way to do it is to use docker-compose run --rm .... for things like composer installs or frameworks CLI utilities you might need. I figured out the ins and outs of bitbucket for private repos with composer and wrote about it here.
  13. Literally the reason for the existence of a span, is that it's display: inline. This respects the style of the parent element. When you set it to inline-block, you are causing it to have "block-like" properties, where it will have margins and padding that effect the box model. You should ask the question as to why the spans you are using have this class applied, and why someone set the style to be inline-block.
  14. I would urge you to adopt most if not all the coding standards in PSR-12 from the PHP Framework Interop group, which has published many useful PHP standards. In particular as mentioned, look at 2.2 which tells you to omit a php end tag. Do this whenever and wherever you can. In conclusion, your php files should never end with a closing tag, and would only need a closing tag if there is an intermixing of php and html blocks. Even if you do, as ginerjm helpfully demonstrated, you won't ever have a closing tag at the end of the file, regardless of whether the file ended with an html block or a php block.
  15. Please use the <> button in the future, and paste your code into the code window, and set the language appropriately. If your code works, as you stated, then most likely the problem is the configuration of the server. There are a number of php settings that control the size of the data that you can submit. For example, in the php.ini you could set a max filesize to (about) 20mb. post_max_size=20M upload_max_filesize=20M Any changes will require you to restart the webserver, or possibly php-fpm. The details are specific to your web server installation.
  16. +1 from me for this.
  17. One thing to be aware of, is that mysql has made some internal changes in regards to storing of fractional seconds that doesn't make timestamp the big win it once was. A mysql datetime only requires 5 bytes + whatever fractional second storage you need. If you don't use/need fractional seconds, you can have a 5 byte Datetime column, which doesn't come with any of the timestamp properties, quirks or baggage. Use whichever type makes more sense to you.
  18. I'm glad this was said, because I was thinking the same thing -- why use an 8 byte integer, when MySQL has smaller date/time datatypes that also support SQL functions natively, with no conversion or clientside logic required? I have written a few blog posts over the years about these topics, that might be of interest: CURDATE and NOW Find Next Monday About MySQL Timestamps
  19. No worries my friend. I hope others enjoy this thread as much as we did. I don't interact with too many people that have as much interest in SQL/Rdbms, relational design and theory, and db internals as we do. Always a pleasure, and frequently an educational experience to read your posts!
  20. Since we are talking about these plans and optimizations, I think it's good to point this out to @null00 You should always avoid using "LIKE '%something%'". This type of query can not use an index. The explains show this clearly. MariaDB [sakila]> select count(*) from actor; +----------+ | count(*) | +----------+ | 200 | +----------+ So you have 200 rows in your actor table, and even though it attempts to utilize the idx_actor_last_name index on actor, the explain shows that even with a join to the subquery, the portion that looks for '%depp%' "table scans" all 200 rows. +------+--------------+------------+--------+------------------------+---------------------+---------+-------------------+------+---------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+--------------+------------+--------+------------------------+---------------------+---------+-------------------+------+---------------------------------+ | 2 | DERIVED | actor | index | NULL | idx_actor_last_name | 182 | NULL | 200 | Using where; Using index | +------+--------------+------------+--------+------------------------+---------------------+---------+-------------------+------+---------------------------------+ I removed all the query plan steps, except for the part that searches for '%depp%' and you can see in the rows column that it examines all 200 rows. So long as a string can be searched from left to right, wildcards can be used and a btree index is still useful. So if this query is modified to be 'depp%' then it will no longer table scan the actor table, but instead will find the only actor row that matches. MariaDB [sakila]> explain SELECT DISTINCT f.film_id, f.title -> FROM film f -> JOIN film_actor fa ON f.film_id = fa.film_id -> JOIN -> (SELECT actor_id -> FROM actor -> WHERE last_name LIKE 'depp%' -> UNION -> SELECT actor_id -> FROM film_actor -> WHERE film_id = -> (SELECT film_id FROM film WHERE title = 'ACE GOLDFINGER') -> ) actid USING (actor_id) -> ORDER BY f.title; +------+--------------+------------+--------+------------------------+---------------------+---------+-------------------+------+---------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+--------------+------------+--------+------------------------+---------------------+---------+-------------------+------+---------------------------------+ | 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 6 | Using temporary; Using filesort | | 1 | PRIMARY | fa | ref | PRIMARY,idx_fk_film_id | PRIMARY | 2 | actid.actor_id | 1 | Using index | | 1 | PRIMARY | f | eq_ref | PRIMARY | PRIMARY | 2 | sakila.fa.film_id | 1 | | | 2 | DERIVED | actor | range | idx_actor_last_name | idx_actor_last_name | 182 | NULL | 2 | Using where; Using index | | 3 | UNION | film_actor | ref | idx_fk_film_id | idx_fk_film_id | 2 | const | 4 | Using where; Using index | | 4 | SUBQUERY | film | ref | idx_title | idx_title | 514 | const | 1 | Using where; Using index | | NULL | UNION RESULT | <union2,3> | ALL | NULL | NULL | NULL | NULL | NULL | | +------+--------------+------------+--------+------------------------+---------------------+---------+-------------------+------+---------------------------------+ 7 rows in set (0.00 sec) Really when you look at it, for this query, a wildcard search of name doesn't make much sense, even with 'depp%', but I guess this is for homework/test prep. In general, you never want to use LIKE '%something%'. If you need full text search then use a fulltext engine or mysql's FULLTEXT indexing and searching syntax.
  21. Yes, much faster, but why? The explains are nice (since we're conducting a mini- mysql class here 😃. I do like your application of USING ... really nice reduction of syntax, although the plans are exactly the same if you utilize the full ON syntax. Nested Subquery: MariaDB [sakila]> explain SELECT DISTINCT f.film_id, f.title -> FROM film f -> JOIN film_actor fa ON f.film_id = fa.film_id -> WHERE fa.actor_id IN -> (SELECT actor_id -> FROM actor -> WHERE last_name LIKE '%depp%' -> UNION -> SELECT actor_id -> FROM film_actor -> WHERE film_id = -> (SELECT film_id FROM film WHERE title = 'ACE GOLDFINGER') -> ) -> ORDER BY f.title; +------+--------------------+------------+--------+------------------------+----------------+---------+------------------+------+----------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+--------------------+------------+--------+------------------------+----------------+---------+------------------+------+----------------------------------------------+ | 1 | PRIMARY | f | index | PRIMARY | idx_title | 514 | NULL | 934 | Using index; Using temporary; Using filesort | | 1 | PRIMARY | fa | ref | idx_fk_film_id | idx_fk_film_id | 2 | sakila.f.film_id | 1 | Using where; Using index; Distinct | | 2 | DEPENDENT SUBQUERY | actor | eq_ref | PRIMARY | PRIMARY | 2 | func | 1 | Using where | | 3 | DEPENDENT UNION | film_actor | eq_ref | PRIMARY,idx_fk_film_id | PRIMARY | 4 | func,const | 1 | Using where; Using index | | 4 | SUBQUERY | film | ref | idx_title | idx_title | 514 | const | 1 | Using where; Using index | | NULL | UNION RESULT | <union2,3> | ALL | NULL | NULL | NULL | NULL | NULL | | +------+--------------------+------------+--------+------------------------+----------------+---------+------------------+------+----------------------------------------------+ 6 rows in set (0.00 sec) Join to Subquery: MariaDB [sakila]> explain SELECT DISTINCT f.film_id, f.title -> FROM film f -> JOIN film_actor fa ON f.film_id = fa.film_id -> JOIN -> (SELECT actor_id -> FROM actor -> WHERE last_name LIKE '%depp%' -> UNION -> SELECT actor_id -> FROM film_actor -> WHERE film_id = -> (SELECT film_id FROM film WHERE title = 'ACE GOLDFINGER') -> ) actid USING (actor_id) -> ORDER BY f.title; +------+--------------+------------+--------+------------------------+---------------------+---------+-------------------+------+---------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+--------------+------------+--------+------------------------+---------------------+---------+-------------------+------+---------------------------------+ | 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 204 | Using temporary; Using filesort | | 1 | PRIMARY | fa | ref | PRIMARY,idx_fk_film_id | PRIMARY | 2 | actid.actor_id | 1 | Using index | | 1 | PRIMARY | f | eq_ref | PRIMARY | PRIMARY | 2 | sakila.fa.film_id | 1 | | | 2 | DERIVED | actor | index | NULL | idx_actor_last_name | 182 | NULL | 200 | Using where; Using index | | 3 | UNION | film_actor | ref | idx_fk_film_id | idx_fk_film_id | 2 | const | 4 | Using where; Using index | | 4 | SUBQUERY | film | ref | idx_title | idx_title | 514 | const | 1 | Using where; Using index | | NULL | UNION RESULT | <union2,3> | ALL | NULL | NULL | NULL | NULL | NULL | | +------+--------------+------------+--------+------------------------+---------------------+---------+-------------------+------+---------------------------------+
  22. My take on this, is that it makes more sense if you can break it down into problems: 1. What list of actors (actor_id) do you need? You need actors with a name like "depp" AND actors who were in the 'ACE GOLDFINGER film". This 1st query gets you those actors. SELECT actor_id FROM actor WHERE last_name like '%depp%' UNION SELECT actor_id FROM film_actor WHERE film_id = (SELECT film_id FROM film WHERE title = 'ACE GOLDFINGER'); To get the full list of films, you need to get all the films for any of those actors, so you have to join your list of actors to the film_actor table, so one very simple way to think about this, is to use some subqueries fed into the upper query. The original query, can be used as a subquery to get you the list of actors. SELECT DISTINCT f.film_id, f.title FROM film f JOIN film_actor fa ON f.film_id = fa.film_id WHERE fa.actor_id IN (SELECT actor_id FROM actor WHERE last_name LIKE '%depp%' UNION SELECT actor_id FROM film_actor WHERE film_id = (SELECT film_id FROM film WHERE title = 'ACE GOLDFINGER') ) ORDER BY f.title; Here's another syntactical take, joining to the subquery rather than using IN SELECT DISTINCT f.film_id, f.title FROM film f JOIN film_actor fa ON f.film_id = fa.film_id JOIN (SELECT actor_id FROM actor WHERE last_name LIKE '%depp%' UNION SELECT actor_id FROM film_actor WHERE film_id = (SELECT film_id FROM film WHERE title = 'ACE GOLDFINGER') ) as a ON fa.actor_id = a.actor_id ORDER BY f.title; And here's a version, where the 'ACE GOLDFINGER' query is also a join to a subquery. This one is probably a bit more correct, in the case that there was more than one 'ACE GOLDFINGER" titled film, that might have different actors. SELECT DISTINCT f.film_id, f.title FROM film f JOIN film_actor fa ON f.film_id = fa.film_id JOIN (SELECT actor_id FROM actor WHERE last_name LIKE '%depp%' UNION SELECT actor_id FROM film_actor JOIN (SELECT film_id FROM film WHERE title = 'ACE GOLDFINGER' ) as ace ON film_actor.film_id = ace.film_id ) as a ON fa.actor_id = a.actor_id ORDER BY f.title;
  23. @Barand: The way the question is posed, isn't the clearest, but I think what is wanted is a list of films that a) has an actor named "depp" or "featured any of the actors in film_id = 2". The result set should be films and not films or actors. I based this off the initial description:
  24. I decided to go ahead and do a test, and this is the alternative version with getComputedStyle. function toggleResponseArea() { let el = document.getElementById("commentResponse") let responseAreaState = window.getComputedStyle(el).display; console.log(responseAreaState) if (responseAreaState == "none") { console.log("none") document.getElementById("commentResponse").style.display = 'block' } else if (responseAreaState == "block") { console.log("block") document.getElementById("commentResponse").style.display = 'none' } return false }
  25. Here is the crux of your issue (aside from the = vs == issues). The style value from document.getElementById is unavailable until you actually use it. So in your case, your code didn't run with the if-else, because no property was ever matched. You can see the state of the styles are not initialized by adding a console.log(document.getElementById("commentResponse")) Here is a way to workaround that if you want to use it. This assumes that the style of the element is display: none as you described. Another alternative would be to set the value initially to 'none' with javascript. function toggleResponseArea() { let responseAreaState = document.getElementById("commentResponse").style.display; console.log(responseAreaState) if (responseAreaState == "none" || responseAreaState == "") { console.log("none") document.getElementById("commentResponse").style.display = 'block' } else if (responseAreaState == "block") { console.log("block") document.getElementById("commentResponse").style.display = 'none' } return false } There is an alternative javascript function: window.getComputedStyle, that you could use to get an accurate value whereas, currently you get an empty value ("")
×
×
  • 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.