-
Posts
5,992 -
Joined
-
Last visited
-
Days Won
150
Everything posted by gizmola
-
Going insane. Ajax call sets session as expected but does not persist.
gizmola replied to jtorral's topic in PHP Coding Help
Basically what is being described to you is a race condition. You aren't going to be able to hack around it. A PHP script runs on the server, and has "page/request" scope. The client provide an HTTP request, and the server provides an HTTP response, and the connection is closed. Ajax is used to make changes to the state of a fully rendered DOM on the client. You are not going to be able to trick PHP into doing some of its work -- delaying while the client's DOM is in a partial/indeterminate state, in order for ajax to spawn another request, and then have the original PHP script resume in the way you hope it will, all so that you can get access to session variables that didn't even exist when the original HTTP request was made. I have no idea why you are trying to store some client state in a session, given that browser dimensions are dynamic, relative to the device and decisions made by the client. It's not clear what you expect to do with these dimensions, which you're getting from javascript code, but you certainly don't need to put them into a session, and you haven't made an attempt to explain what problem you are trying to solve, but this is not the way to solve whatever problem that is. If you want to actually take the time to explain the "problem to be solved" we might be able to better advise you on ways to solve it. -
Correct.
-
No. In the code I provided I loop through your array and get each name attribute, then call document.getElementsByName(). As I mentioned what you get back is a nodeList. This is because when you call GetElementsByName the result can be 0 or more nodes, as you are able to use the same name attribute for any number of html elements. In this case, even though that is true, it's your markup and we know that there should only be one node found, and that will be the input that matches the name you passed. As arrays are zero based, item[0] will be the first (and since you control the markup) only element in the nodelist. You can think of it as an array that has only one element in it. As to what you came up with, using eval() should be avoided, as it's highly dangerous to the end user, should there be any possibility that someone can inject a string containing javascript into the string. You continue to attempt to reference part of the DOM document this way, when you already were presented 2 ways NOT to do that, either of which will work. As we don't know the actual form of these numbers that you require for input, we can't really advise you. isNaN by itself is not going to do what you stated you want to do. Here's a couple of examples: let foo = ''; let bar = '0xFF'; isNaN(foo); isNaN(bar); A quick test of these should be of concern to you. If the numbers entered must be integers then mac's Number.parseInt() might lead you to a robust and simple solution. An alternative is to utilize javascript's regular expression syntax. You might also try typecasting values. One thing to keep in mind here, is that in doing what you are doing, as you manipulate these values, you are creating new variables, but the original input values will still be in text form, so even if the data passes through your form validation, the values may be problematic at the point you store them in a database or whatever the app does.
-
I'm sure he does know that, and we are both motivated by an interest in mentoring and passing along our expertise to people like yourself if we are able. We appreciate the feedback.
-
I was going to suggest something similar to mac's post, however, I think a better UI choice would be to use AddEventListener to all the fields for the change event using getElementsByClassName to find them. There's an awful lot wrong with what you have so far, not to mention that you have yet to come up with any code that determines if a text input is actually a numeric value. It is deceptively complicated and non-trivial to do so, but that issue aside, what you were asking about could be remedied using code like this. One thing I noted is that you are trying to make a lot of global variables for no particular reason. Try to get in the habit of making as few variables as possible, and use ES6 let and const rather than var (which makes a global variable). What you were missing is the DOM method document.getElementsByName. It returns a nodelist, so make sure you investigate that. I did not try and provide you a solution to your stated goal, but rather, something that moves your work in progress forward, and omits issues with the pattern you are missing. Using this as a form validation means you can't return true for any individual element, but only return true when all elements successfully validate. So you do that by falling through to a return true at the end of the loop. There are several problems even with this code, but hopefully it helps move you forward from where you started. const arrayone= ["it_c","it_h","ot_c","ot_h"]; function hasNumericValue(arr) { // check for numeric values posted in the array of the input fields for (let i = 0; i < arr.length; i++) { let item = document.getElementsByName(arr[i]); let linker = item[0].value alert("Checking Field: " + arr[i]); if (linker == 10) { alert("Value was 10"); } else { return false; } } return true; }
-
Yes this is common practice. When you first introduce a table you can alias it. You are then free to alias all the columns which can be quite a time saver when you have joined tables together, using "alias.column_name" as Barand did. You can do this explicitly using the 'AS' keyword but you can also omit the 'AS'. It's up to you, but I typically will abbreviate the name in some way, as do most experienced developers, such that your alias is at most a few letters. You should also notice, that he used an alias for the computed columns. Column names can also be aliased, and it's also a common practice. FROM_UNIXTIME(t.time) AS time So in this case you have an example of both alias options being used: thread table was aliased to t Used the t alias to specify the time thread.time field being passed to the FROM_UNIXTIME() SQL function the result of the function being aliased to the name 'time' in the final result set Also time was used in the order by. MySQL allows you to do this (use an aliased column name in an ORDER BY) although not all RDBMS do.
-
Barry is truly a master of relational database design, implementation and SQL. However , at least initially, a small investment on your part in learning how to join tables together, will dramatically improve your understanding of his analysis and the SELECT statement he provided you. I browsed this material and it's a solid free tutorial on Joins using MySQL. https://www.mysqltutorial.org/mysql-basics/mysql-join/ You may see references to ANSI standard SQL, which is a standard for portable SQL syntax that should be compatible with most relational databases, but I did want to mention that different databases will have features that are specific to their implementation (non-standard), so you might see that in the case of joins there is more than one syntax possible, but they all do the same things. Don't let that confuse you -- JOINS are an essential concept that all relational databases implement. If you have an option, and can use ANSI standard syntax, opt for that, but it really doesn't matter that much, so long as you are clear on what the join produces. A basic understanding of Set theory might give you some insight into the ideas that went into relational database management (union, intersection, difference, subset) might help as well. This article cover the topic pretty well, and you may notice some of the overlap in concept and terminology: https://kyleshevlin.com/set-theory/ It's also worth learning how to read an Entity-Relationship-Diagram (ERD). Once you understand the fundamentals, you should be able to look at an ERD and understand how tables can be joined together. There are also many tools that people use to design or reverse engineer databases. For example, mysql provides ERD design features in their free SQL Workbench tool. ERD's are the way that people socialize a database design, and are the documentation that teams use to document for developers, the database design.
-
No problem, if we thought it should be moved we would have moved it previously. Glad we were able to help you out.
-
The first thing you need to be clear about is what a literal string is vs. an interpolated string. As this is an important fundamental, I'll assume you know which is which in the following examples. A key can be any sort of valid PHP string. So this makes it possible to get yourself into a lot of trouble potentially. One caveat, as you will see, is that even if you specify a literal string, if PHP determines that string is equivalent to an integer value, it will create an array element indexed by the value. So you can't have an array key of $r['3'] and $r[3]. Also, you should notice that it will cast a float to an integer, and that this behavior is deprecated, so clearly you don't want to ever try and use a float as a key, even though it will actually work (sort of), in that it converts the float to an integer. <?php $foo = 'bar'; $s = array(); // Anything that looks like an integer, PHP will convert to a numeric key $s["0"] = 'Apple'; $s['1'] = 'Banana'; // Notice it casts the flaat to an int and gets 2 $s[2.85] = 22.072; // However if they are strings, you can key on floating point values $s['2.85'] = 2.85; $s["2.86"] = 2.86; $s['$foo'] = 'literal'; $s["This is $foo"] = 'interpolated'; $s['.foo.bar'] = 'dot foo dot bar'; $s["\u{1CC0}"] = 'unicode'; var_dump($s); Here's the var_dump result: Deprecated: Implicit conversion from float 2.85 to int loses precision in php-wasm run script on line 10 array(9) { [0]=> string(5) "Apple" [1]=> string(6) "Banana" [2]=> float(22.072) ["2.85"]=> float(2.85) ["2.86"]=> float(2.86) ["$foo"]=> string(7) "literal" ["This is bar"]=> string(12) "interpolated" [".foo.bar"]=> string(15) "dot foo dot bar" ["᳀"]=> string(7) "unicode" }
-
If the php.exe executable is in your windows path, you probably won't have to manually add the path to that configuration. In fact you would likely need to delete the value from vscode. 1st to understand what the path environment variable does. When you try and run a program, windows will look for that program in the current directory. If it is not found, then it tries to find it in the path. So by design the path variable should have directories in it, NOT the full pathname to the program. So in your example the path you want to add is: C:\laragon\bin\php\php-8.4.3-Win32-vs17 x64\ Follow these instructions to add the location of your laragon php directory file to your system path: These directions were for Windows 10, but they also work for Windows 11. Make sure you don't overwrite your current path, but instead just edit it by adding the path to your php8x installation. Let us know if that fixes the problem. Make sure you restart Vscode after you have added the laragon path to your windows path variable.
-
Yes. It wants a local copy of PHP on your workstation. I do have to point out that PHP 7.4 was end of life 2 years ago now. It would be best if you upgraded to a more current supported version of PHP ( > 8.1 at this point in time).
-
You are starting with File1 and you diff it using FIle2. What do you get? You get a Diff file telling you how to change File1 into FIle2. The use case for diff-ing was as a tool for "authors" (in the olden times when diffs were commonly used to distribute updates to text based files) to provide patch files to "end users" who would use a patching tool to transform their files into the "patched" state. In the modern era, there are just better more reliable and resilient ways of distributing updates. Clearly, in this case the xml diff file shows exactly what would be expected when you give it a diff that is based on a file that has nothing but a new element. It deletes the original element, adds the new one, and leaves you with ..... file2. It's hard to say whether or not this is worth doing, even if it works, given this is sample data, however, you might try reversing the order of the parameters -- create a diff where you: $diff = $dom->diff($x2Doc, $x1Doc); I am not sure how it will resolve the 2 different attributes, but at least in this case, I suspect that it might generate the ultimate result you expect.
-
Since you have no PHP code, I have to conclude that this is not a PHP question. You are also apparently using Dropzone.js (or at least that is an educated guess), so I'm moving this to the right area of the site for javascript questions.
-
You are certainly not showing us the actual code you are using, or there is something in your debugging because sizeof/count returns an int. So the sizeof is not echoing 154[]. Something is echoing 154 and then something else is echoing out the "[]" which is an empty array. One thought I had is that this issue could have something to do with your query(s) and what is in your database. A common mistake (and one you are making here) is to assume you will be getting one row in a result set, and then fetching that result with fetchAll. If you only expect one row, then the query should reflect that, as well as the code you use to fetch the row(s) from the result. It occurred to me, that you might be getting what is essentially an empty row in your result set, or getting 2 rows when you only expected one. I can't say for sure that this is the issue, but it's a possibility, given the snippets of code you've provided so far. Your query is doing a lot of joins, and any confusion on your part or extra rows in the joined tables will generate additional rows in the result set as a product of the join.
-
Here you go: $json = '[ { "place_id": 329211526, "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "osm_type": "way", "osm_id": 19239538, "boundingbox": [ "34.6786854", "34.6787122", "-77.5843465", "-77.5835107" ], "lat": "34.6787013", "lon": "-77.5840059", "display_name": "West Main Street, lex, Troy Township, BIGG County, Ohio, 44333, United States", "class": "highway", "type": "primary", "importance": 0.6000099999999999 }, { "place_id": 329211743, "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "osm_type": "way", "osm_id": 38610646, "boundingbox": [ "34.6787122", "34.6871188", "-77.603118", "-77.5843465" ], "lat": "34.6827021", "lon": "-77.5937807", "display_name": "West Main Street, lex, Troy Township, BIGG County, Ohio, 44333, United States", "class": "highway", "type": "secondary", "importance": 0.6000099999999999 }, { "place_id": 329180475, "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "osm_type": "way", "osm_id": 823017968, "boundingbox": [ "34.9201281", "34.9214493", "-81.1346294", "-81.1251686" ], "lat": "34.9208004", "lon": "-81.1297602", "display_name": "West Main Street, Alliance, lex Township, Stark County, Ohio, 44601, United States", "class": "highway", "type": "tertiary", "importance": 0.6000099999999999 }, { "place_id": 329179580, "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "osm_type": "way", "osm_id": 19258266, "boundingbox": [ "34.9095347", "34.9189094", "-81.1539336", "-81.134635" ], "lat": "34.9146373", "lon": "-81.1445334", "display_name": "West Main Street, Alliance, lex Township, Stark County, Ohio, 44601, United States", "class": "highway", "type": "unclassified", "importance": 0.6000099999999999 } ]'; $data = json_decode($json, true); echo "latitude: {$data[0]['lat']} longitude: {$data[0]['lon']}"; Things to understand: json_decode can either create an array of php objects or a php array. Choosing array typically is simpler. Thus I passed true as the 2nd parameter to json_decode(). Javascript arrays (as they can now be represented in php as well) are enclosed in square brackets. [ ... this is an array of stuff ] The first structure in the array will array key 0 In this case your data is an array of javascript objects (the "name": value pairs) From there, all you need to do is reference the key value for the element you want. Therefore you get $data[0]['lat'] for the first array element 'lat' key from the original json object.
-
install the php8.2-xml extension
gizmola replied to rick645's topic in PHP Installation and Configuration
You don't need that package (php8.2-xml). XML support is already installed by default in the base 8.2 image. -
install the php8.2-xml extension
gizmola replied to rick645's topic in PHP Installation and Configuration
Did you try to remove those lines and if so, since they were redundant and problematic, what result did you have? You could also provide the Dockerfile you are using, which would allow others to recreate your experience. -
install the php8.2-xml extension
gizmola replied to rick645's topic in PHP Installation and Configuration
Install via apt should take care of installation of the extension, so I don't think you need these: && docker-php-ext-install php8.2-xml \ && docker-php-ext-enable php8.2-xml -
php form coding works on Safari but not on Firefox
gizmola replied to cearlp's topic in PHP Coding Help
Can you put your code in a code block in the future? Reading/looking at double spaced code without proper indentation or color syntax highlighting wastes everyone's time and effort and greatly decreases the final results. Notice @Moorcam helpful reply to you where he put an offending line into a proper block where the issue is easy to identify. -
Most people use Cloudflare for the proxy and edge caching. DNS registration is a commodity. There are plenty of other registrars like Cheapdomains you could look at purely for DNS registration. You can always make a free Cloudflare account and explore their offerings. They provide a lot of useful features in their free account.
-
Possible to have a single MySQL query for multiple items?
gizmola replied to wrybread's topic in PHP Coding Help
It does sound like mac_gyver had the solution. I'm going to assume that your solution was something like: "SELECT * FROM descriptions WHERE `item` IN ('rolls', 'baguettes', 'croissant')". You should have an index on the 'item' column as well, if you don't. I'm a stickler for data consistency, and perhaps this was just an arbitrary example you created, but if you are going to use plurals (rolls, baguettes) then all of these should be pluralized, and you shouldn't have singulars like 'croissant' or 'donut'. My main comment, is that there is no benefit to using LIKE unless you are using wildcards. LIKE works fine when you actually need it as in: WHERE name LIKE "sm%" finding "Smith", "Smith Jr." and "Smeely", etc. If however, you attempt to find a substring as in: WHERE address LIKE "%main$" This defeats the ability of the database to use indexing. The queries will work, but assuming this is the primary criteria, will need to tablescan the entire table looking for addresses that have 'main' somewhere in them. If the dataset is relatively small, these types of "% ... %" or "% ..." queries are acceptable, but if the dataset is large, you may find you are having significant issues. -
This is typically where a pub-sub solution helps. As you mentioned, the old school ways of hacking ajax to do this involved polling. Websockets were introduced to provide a better solution, but have the downsides of being an entirely different protocol, requiring a websocket server. Some people get somewhat around this by utilizing a websocket PAAS, at least for me, the best known of which is Pusher. When I last utilized it, the economics were very reasonable, and for a site with known relatively low traffic there's a free tier. There are alternatives, but if you really need bi-directional communication, websockets are the best solution. If however, this is simply a "push" requirement to "publish" to the "subscribers" then there is now a standard feature you can use known as "server sent events (SSE)". Support for this is very good at this juncture as you can see here: https://caniuse.com/eventsource SSE sounds tailor made to solve your problem here, as your updates can be pushed out to all your clients. Here's the MDN page for the feature. I know of a few php libraries that that have all the serverside plumbing taken care of: https://github.com/hhxsv5/php-sse https://github.com/clue/php-sse-react I will caution that there is no free lunch. SSE's are better than (long) polled ajax, but they still require a dedicated socket connection per client. Anything like this requires significantly more resources, but if it is an essential feature of your application, SSE could be tailor made for what you want, although you should also evaluate using Pusher as an alternative.
-
Is pro mysql the best book to learn mysql administration?
gizmola replied to oslon's topic in MySQL Help
I don't know that there is a best book. MySQL has been around for a long time, and due to its origin as an open source database with a GPL license, as well as it's relatively unique pluggable engine, it has been extended and forked. Oracle acquired MySQL and at that point, the original MySQL developer forked the code and created MariaDB. Percona also has a fork. So there are now a variety of flavors of "MySQL" with different features and versioning. Whatever book or resource you might get, you want to be sure it is relatively recent and contains information based on the most recent MySQL releases. If your focus is administration, there is a lot of general use content in that book. A book that is more focused on administration like this one might be better. To be clear, I have no experience with any of these books. If you have used a Udemy account, and you are patient, you can routinely license courses for under $10 US. That might be a cheaper way to get similar training. You might consider starting with youtube and looking for other online resources, and combine that with use of the official MySQL docker instance to experiment and learn. -
How to ECHO which item was found/matched after running "foreach"
gizmola replied to myphp's topic in PHP Coding Help
The code Psycho provided is a fairly standard way of solving this problem. Notice how he made use of the empty() function. Empty works well here, because it will return false if it receives an empty array, and true for anything else. -
Examples of php scripting projects without laravel?
gizmola replied to oslon's topic in PHP Coding Help
Certainly you are pushing the limits on a workstation with a processor that was released 12+ years ago. With that said, my guess is that you might have limited memory available? Rather than trying to use Kubernetes, you should try this image: https://github.com/deviantony/docker-elk It comes with a docker-compose.yaml file, so you basically just "docker compose up". They indicate that you need 1.5gb available, which is not an unusually large amount of memory, considering you are running 3 orchestrated containers. If your workstation is highly constrained on memory, then virtualization of any kind is probably going to be somewhat slow and potentially not very enjoyable. With that said, I did an awful lot of work in vm's using vmware workstation, virtualbox, vagrants etc, on machines back in the i5/i7 era.