Jump to content

Phi11W

Members
  • Posts

    112
  • Joined

  • Last visited

  • Days Won

    9

Phi11W last won the day on February 1

Phi11W had the most liked content!

1 Follower

Recent Profile Visitors

1,406 profile views

Phi11W's Achievements

Advanced Member

Advanced Member (4/5)

25

Reputation

4

Community Answers

  1. Could it be as simple as json_decode( JSON_data_In_a_String_variable )? Regards, Phill W.
  2. But if you validate and then redirect, then the page at the end of that redirection must repeat the validation, otherwise someone could send data to it directly, bypassing the validation. The basic pattern for my pages is something like this: if ( form data submitted ) { Validate form data - populate variables and error messages ; if ( form data valid ) perform any required Action ; } Display Form, with values and/or error messages and/or results from the Action. Any "validation" that you do in Javascript on the client is for the Users' convenience only - you must not rely upon it because nothing that comes from the client can be trusted. (For example, do you validate the form value submitted from the HTML "select" list that you sent? You probably should ...) Regards, Phill W.
  3. Remember that you're building a PHP String that just happens to contain some text (SQL) that means something to your database. You have to build tat string according to PHP rules: $query=$bdd->prepare('SELECT t2.ui_company, t1.* FROM a2billing.nwc_refill_users t1 LEFT JOIN a2billing.nwc_anagrafica t2 ON t1.refag_richiedente = t2.ui_login WHERE t1.refag_paga_a=\'\' AND t1.refag_importo > 0 AND t1.refag_dataora_validazione<>\'\' AND (DATE(t1.refag_dataora)>=\'2022-01-01\' AND DATE(t1.refag_dataora)<=\'2022-05-15\')'); You might also consider using Parameters in place of the literals. A tiny bit more code but you'll avoid headaches like this. Regards, Phill W.
  4. Well, yes it does, because that's what's in your data! What you're missing is the action that caused each row to appear in your results. Include the action column and your data should make a little more sense. What are you trying to achieve? Calculation of total stock levels based on actions against each item? For that you'd want something like this: select id , sum( case action when 'Added Qty' then poqty when 'Stock Received' then received_qty when 'Outgoing Record Recorded' then - outgoing_qty /* negate value to deduct from total */ end ) qty from table1 group by id order by action ; Bear in mind that ordering by a text field (whose values might change over time) could give you headaches. It might be better to codify these values (into a "Lookup" Table) so that you can sequence them reliably. Regards, Phill W.
  5. In almost every DBMS by default, and MySQL if you configure it properly, this query will be flatly rejected as an error. What values of ponum and status would you expect to be returned when you are only grouping by itemname? The fields that you select either must be included in the "group by" clause or must be used in aggregate functions, like SUM. Suppose you had a number of purchase orders - what output would you expect to see for these "extra" fields? +-------+------------+------------+-----+ | ponum | status | itemname | qty | +-------+------------+------------+-----+ | 111 | Complete | Keyboard | 1 | | 222 | Complete | Keyboard | 2 | | 222 | Complete | Mouse | 1 | | 333 | InProgress | Keyboard | 1 | | 333 | InProgress | Mouse | 1 | | 333 | InProgress | Chair | 1 | +-------+------------+------------+-----+ select itemname, ponum, status, sum(qty) from ... group by itemname ; +----------+-------+------------+----------+ | itemname | ponum | status | sum(qty) | +----------+-------+------------+----------+ | Chair | 333 | InProgress | 1 | | Keyboard | ??? | ??? | ??? | | Mouse | ??? | ??? | ??? | +----------+-------+------------+----------+ If you can't tell the query which value you want within the grouping, the query should give up and throw an error. MySQL is one of the few DBMS that does not do this by default. Regards, Phill W.
  6. I'm guessing your problem is with this query: You can't "invent" SQL syntax. You have to use what your DBMS supplies to you. The keyword to group two conditions logically and require both to be TRUE is "AND". Whilst the "&&" operator does the same thing in PHP, C# and other languages, MySQL only understands "AND". This bit might cause you problems as well: IIRC, the MySQL Now() function returns the time as well as the date. If you're only storing the date, then the two will never match, as in: '2017-05-28' != '2017-05-28 00:00:00' You'll probably have to do some truncation on the returned value (say, using the DATE() function). Also, read up about Prepared Statements, to protect yourself against SQL Injection Attacks. Obligatory XKCD Reference - Little Bobby Tables. Regards, Phill W.
  7. Obligatory XKCD Reference: Standards Simply, you want to arithmetic on the values. Addition, subtraction, multiplication of numeric values that represent monetary amounts in different currencies. If those values are "buried" inside String values inside a single database field, then you have to waste processing time pulling those values apart so that you can "get at" the numeric part and then do your arithmetic on that. Databases are really, really good a finding bits of data and putting them together. They are [all] generally rubbish at finding big chunks of data and pulling them apart again. This is a case where the storage representation of these values (two fields, one numeric value, one character currency code) is different from the way that you or I might choose to think about them. That representation - the one that we would use - should be delivered by the Application, interpreting what's stored in the database into what we are used to seeing (and reinterpreting values going the other way, from what we use into the database). Regards, Phill W.
  8. (Being a Character Representations of their actual Data Type) Datetime literals must be enclosed in single quotes, in exactly the same way as you do for Character literals. The error message is definitive. Error: INSERT INTO weather_data ... VALUES ( 2022-01-24T15:40:00.000Z, 47.7, 47.7, 30.048, 29.224, 45.49, 92, 314, 1.3, 2.2, 8.1, 0, 0.161, 0.161, 0.681, 49.024, 2022-01-24T15:34:00.000Z, 29.48, 1 ) \_________/ You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':40:00.000Z, 47.7, 47.7, 30.048, 29.224, 45.49, 92, 314, ' at line 6 That said, you should not be embedding variables directly into SQL - you are leaving yourself wide open to SQL Injection Attacked. Use a Parameterised Query (Prepared Statement) instead. Obligatory XKCD Reference - Little Bobby Tables. Regards. Phill W.
  9. Any non-Indian Users that favour keyboard navigation are still going to be very frustrated by this design. As soon as they try to move "down" the list with the arrow keys, the Javascript code will submit the page, including the first option ("country=india"). This reloads the page and, sadly, your code doesn't cater for the list "remembering" which option was chosen previously and just resets itself to the first, "--select--" option. Pressing the down key again just goes round the same loop over and over again (and hits your PHP backend each and every time). Do you really need such real-time handling of a change in country? Regards, Phill W.
  10. Ignoring the dodgy HTML syntax for a moment, remember that only the value of the selected option gets submitted in the HTTP form data, not the [inner text] description. With this in mind, how is your PHP code supposed to tell the difference between the 2nd, 3rd and 4th options (all of which will effectively submit "modSelected=$PostId")? Also, submitting a form on each change of the DropDownlist is likely to lose you major points on the "Accessibility" scale. People will have a very hard time trying to navigate your form using the keyboard. Regards, Phill W.
  11. Why reinvent a perfectly good Wheel? Compound data structures are already rather well catered for by [things like] JSON: $jsonText = '{"foo":["home","food"],"brand":"tulasi"}'; $json = json_decode( $jsonText ); echo count( $json->foo ); // 2 echo $json->brand; // 'tulasi' var_dump( $json ); //object(stdClass)#1 (2) //{ // ["foo"]=> array(2) // { // [0]=> string(4) "home" // [1]=> string(4) "food" // } // ["brand"]=> string(6) "tulasi" //} The problem with your code is that the comma character (",") is being used to separate both the top-level items (foo and brand) and the individual values of foo! The explode() function cannot tell the difference between these two usages of the comma character. Regards, Phill W.
  12. You can work with hyphenated attribute names, but you have to wrap them up a bit more: $var2=$dolar->{'class-variacion'};
  13. The POST'ed values are always Strings. $stok_awal is whatever numeric value comes back in the qty field (we have to assume that this is numeric because, coming from the database, it really ought to be) or zero, if the retrieved value was NULL. $qty is still the String value from the POST'ed data values. [int] + [string] => Error. First validate that the POST'ed value really is [the String representation of] a numeric value and then convert that value to the correct Data Type before using it. Regards, Phill W.
  14. Did you try following the link under "The XY Problem"?? It's asking a very [very] specific question about a solution you're trying to get working when the "correct" answer involves taking a different path altogether, for example: "X" Question: "How can I stop llamas from chewing the cushions on my sofa." (requesting a solution to a very specific, small-scale issue.) "Y" Question: "How do I stop llamas getting into my house." (asking a far broader question, the solving of which would completely eliminate the need for the original solution). Regards, Phill W.
  15. And that would be because brackets matter. This takes the value of the variable $id and binds it to the parameter named :id. This creates a single-element array whose only element is the value of the variable $id and tries to bind that to the parameter named :id. I'm guessing that either PHP doesn't know how to bind arrays to parameters or it's trying to do so, getting an error and then not showing that error to you (i.e. failing silently, which is almost always a Bad Thing). Do you have error reporting enabled? Something like this: ini_set( 'display_errors', 1 ); ini_set( 'display_startup_errors', 1 ); error_reporting( E_ALL ); Regards, Phill W.
×
×
  • 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.