Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Phi11W last won the day on February 1

Phi11W had the most liked content!

1 Follower

Recent Profile Visitors

1,801 profile views

Phi11W's Achievements

Advanced Member

Advanced Member (4/5)




Community Answers

  1. I suspect there might be a typo - most unexpected - in Barand's answer. Perhaps this makes it a little clearer: $stmt->execute( [ $enteredCity, $enteredZipcode ] ); Personally, I'd choose to build the query dynamically, based on which search criteria were entered, then bind the entered values into that, but that may be a bit overkill in this case. Regards, Phill W.
  2. You probably face more problems if you do explicitly close PHP blocks. Unless those "?>" characters are the very last in the file - and they almost certainly won't be, because we naturally hit [Enter] after typing anything on a line - then the whitespace after them will be sent as part of the HTTP response. If, somewhere later on in your code, you try to alter one of the HTTP Headers - BOOM! The web server will complain that it's already sent some "content" - you can't see anything, but the server insist it's there. Omit the closing tags completely and all that whitespace will just be sitting between PHP tokens, where it matters not a jot! Some coding standards actually enforce this. Regards, Phill W.
  3. [Begin Architectural Sanity Check] Are you are doing this in a Web Application, accessed by remote Users, via a URL? If so, you cannot do this (not with PHP). PHP runs on your Application server and can, therefore, only print to a printer connected to your server. That's not much use to a User potentially on the other side of the planet and who has no physical access to your DataCentre, which is where the printed piece of paper would wind up! Nor can you access any printer connected to the User's computer. PHP has no knowledge of this. In short, if the User wants to print a document, then that's entirely up to them. (These days, who's to say they even have a printer!?) [End Architectural Sanity Check] Of course, if this is a "local" PHP [console] application that only needs to talk to your own printer, that's a whole other ball game - forget everything I said above. Regards, Phill W.
  4. The period is the String concatenation operator and PHP isn't fussy about having whitespace around its operators so it should work with either. Personally, I like the spaces. Other people I work with detest them. Go with whichever fits your Coding Standards. 😉 Personally, I would also question the use of ".." in your paths. To me, it suggests that you should be "anchoring" your paths "further up" the directory tree. As it is, you're making assumptions about what's "outside" the directory your script lives in and, if you refactored and moved things around, you could end up breaking things. (That said, this might just be a hang-over from my spending too many years writing ASP running under IIS). Regards, Phill W.
  5. It's not a question of not wanting to help. We do. "Helping" means guiding you, clarifying what confuses you and generally working with you to complete a piece of work. It absolutely does not mean us doing it [all] for you. You've shown us nothing in terms of what you've tried so far, so we can only assume you want us to do for you. We're not going to do your work for you. We're all volunteers around here. We're absolutely not going to do your homework for you. It would be dishonest (both to you and to your fellow students) and you would learn nothing from it. The most effective Learning involves doing - Trying, sometimes failing, learning from those failures and, ultimately, succeeding. So make a start, trying some things out, see what works and what doesn't and come back with specific questions - then we might be able to help. Regards, Phill W.
  6. What creates the IFRAME? Show us your modified code. I'd hope it looks something like this: while( $row = $result->fetch_assoc() ) { printf( '<iframe width="420" height="315" src="%s"></iframe>', $row['url'] ); } Regards, Phill W.
  7. For starters, do you actually care about the individual referrers' names or just the [total] number of them? Your code currently retrieves each and every referrer and "manually" counts them. It's far, far more efficient to get your database to do that for you: $find_referrals = $db->prepare("SELECT count( user_id ) tally FROM user_referrals WHERE sponsor = :sponsor"); This will return you the number of referrers directly. Now, at first glance, you might think that your second level referrers query needs those user_ids in order to find their referrers. Doing this in code is a really Bad Idea - it's called the "1+N Query" Model and it's a nightmare for Application performance. As the number of "secondary" queries ("N") grows, your Application slows to Run like a Slug(TM). It's unscalable and untunable; there's nothing that can be done at the database end of things to improve matters. Instead, you can get your database to retrieve the second level referrers based on the original sponsor and their referrers, something like this: SELECT count( lvl2.user_id ) tally FROM user_referrals lvl1 LEFT JOIN user_referrals lvl2 ON lvl2.sponsor = lvl1.user_id WHERE lvl1.sponsor = :sponsor ; Regards, Phill W.
  8. "in phpmysql I have a table ..." Google Chrome is an Application that lets you work with Web Pages (that run inside a Web Server process like Apache). PHPMyAdmin is an Application that lets you work with Databases (that run inside the MySQL DBMS process). "... a table with one of the columns... I want to show a live price in ... At the moment I the column is set as varchar(30) do not know if this is correct." In short - It's not. Always store your data values in columns of the correct Data Type. You will want to do numerical things with these values (like adding them up) so you want then in a numerical column type. If you don't do this then: your queries will run more slowly because the database has to convert the character value into a number each and every time you use it, and You run the risk of losing numerical accuracy (e.g. rounding errors) during those "implicit" Type Conversions. "In my html table I want to add 3 or more if/else in, so when I update my html it must show 0.03234523 (depending on the price) I do not want all the rows to show this information" If you only want to hold values in your table for particular rows, then you need to consider making the column NULLable so that you can "leave out" that particular field in any given row. If you only want to suppress the value visually in the HTML (which, if I'm honest, seems a bit odd to me, given that this is the price of something) then you'll need to keep track of (or go and find) the price value from the previous row and, only output the current value if it is different from that previous one. Regards, Phill W.
  9. Something like this? for ( var i = 0 ; i < length ; ++i ) { if ( ( 0 = ( i % 5 ) ) && ( 0 != i ) ) result .= '-' ; result .= characters.charAt(Math.floor(Math.random() * charactersLength)); } Regards, Phill W.
  10. Barand's point is that you don't need the enabled field at all. Your application should allow submissions when the current date/time is between entrytime and closetime. At any other time, it should not allow submissions. Showing which items are available is a problem for the client web page - Javascript's much better at that sort of thing. (Of course, your server-side Application still needs to check those date/times!) Having databases try to update themselves in near-real time is a pretty difficult undertaking and assumes that your database is always, always available and working and properly. Take it from a 30+ year professional ... 100% Availability is a Myth. Regards, Phill W.
  11. Could it be as simple as json_decode( JSON_data_In_a_String_variable )? Regards, Phill W.
  12. 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.
  13. 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.
  14. 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.
  15. 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.
  • 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.