Jump to content

gizmola

Administrators
  • Posts

    5,992
  • Joined

  • Last visited

  • Days Won

    150

gizmola last won the day on February 2

gizmola had the most liked content!

7 Followers

About gizmola

Contact Methods

  • Website URL
    http://www.gizmola.com/

Profile Information

  • Gender
    Male
  • Location
    Los Angeles, CA USA

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

gizmola's Achievements

Prolific Member

Prolific Member (5/5)

352

Reputation

68

Community Answers

  1. 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.
  2. Correct.
  3. 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.
  4. 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.
  5. 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; }
  6. 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.
  7. 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.
  8. No problem, if we thought it should be moved we would have moved it previously. Glad we were able to help you out.
  9. 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" }
  10. 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.
  11. 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).
  12. 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.
  13. 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.
  14. 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.
  15. 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.
×
×
  • 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.