Jump to content
Larry Ullman's Book Forums

HartleySan

Members
  • Posts

    3047
  • Joined

  • Last visited

  • Days Won

    243

HartleySan last won the day on March 7 2019

HartleySan had the most liked content!

Recent Profile Visitors

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

HartleySan's Achievements

Newbie

Newbie (1/14)

  • First Post Rare
  • Collaborator Rare
  • Posting Machine Rare
  • Week One Done Rare
  • One Month Later Rare

Recent Badges

826

Reputation

  1. Hey, Seifer, replying way after the fact. As a general flow, you'll probably want to have a function that renders all the cards based on what's in the array, another function for adding items to the array and a third function for deleting things. Lots of pseudo-code here, but the render function would be something like the following: const render = () => { let html = ''; html += '<ul>'; items.forEach((item) => { html += `<li> // More HTML here for each card </li>`; }); html += '</ul>'; document.querySelector('wherever-you-want-to-put-the-html').innerHTML = html; }; Then, every time a change is made to the items array, you simply call the render function and it does everything for you. This is very similar to how React/Vue, etc. work behind the scenes. The add and remove functions would be something like the following: const add = (item) => { items.push(item); render(); }; const remove = (idx) => { items = items.filter((item, i) => i !== idx); render(); }; Again, being very rough here, but that's the basic flow, and everything else goes around this. You can style things and add whatever functionality you want on top of this. Good luck!
  2. sam, there are a lot of ways you can do this, and there's no "right" answer. I think #1 and #2 in your list are fine. Usually, in a modern MVC (model-view-controller) approach, you DB query for a user would take place in the user model, and your controller that receives the Ajax request would make the call to the user model to begin with. More simply though, if you have a user class, in the script that receives the Ajax request, you can call methods in the user class however you see fit, and once you have all the data you need from the DB, yes, I would package it up into a logical format and send it back via JSON. At that point, JS can do whatever it wants from the Ajax response to render the data accordingly.
  3. Hi, sam67. I'm not Larry, but if you don't mind, I'll chime in with my two cents: For the most part, how you structure your PHP (procedural vs. OOP, etc.) doesn't really affect an Ajax request from JS and vice versa. What I mean is, whether a request comes from a standard browser request or an Ajax request, PHP is more or less going to receive it the same way. The request is just a request, possibly with some data attached as a payload, and how you choose to handle that request in PHP is up to you. At least, that's my immediate response to your question. I could be completely misunderstanding what you're asking though, so if maybe you could provide some more info and clarify where I'm maybe misunderstanding you, maybe I can help more. Thank you.
  4. I think so, yes. To me, Larry's books have always been about teaching the fundamentals really well, and then it's up to you to take that knowledge and apply it. I don't think the fundamentals have changed at all since that book came out. Once you get through the book and understand what it's saying, you can very easily go through all the changes in all subsequent PHP versions and pick them up. The changes are nothing revolutionary. Once you get through the book, if you want to then focus on something that's most likely to get you a job / help you start a career, I would learn a modern PHP framework that's still very relevant. Laravel instantly pops to mind as I write that. Good luck!
  5. Disabling a checkbox in JS is actually really easy. You simply do the following: checkboxDomElem.disabled = true; And you can toggle the checkbox back on by setting disabled to false. The trick is writing the correct logic in your JS (or PHP, and then pass it over to your JS) that knows that when you click a particular checkbox in the first row to disable three particular checkboxes in the second row, etc., etc. For that, there are any number of things you can do, but I personally prefer Vue.js these days. It's an extremely powerful JS framework that makes this stuff easy. With it, you essentially just have to pass it a dependency tree, so that it knows which checkboxes are conditionally dependent on which others and you're done. Good luck!
  6. A 404 error is a page-not-found error, which means that your server cannot find the script in question. In other words, the URL to the file is probably incorrect. Within the xampp folder, where is the script stored, and is your Apache server running? Thanks.
  7. kbear, are you using some third-party library or did you build the slide-out yourself? If it's the former, then you'll have to check the documentation for the library, as there's likely an option to prevent it from sliding in/out on page load. If it's the latter, well, that's your code, so you'll have to program whatever you need to stop it from happening on page-load.
  8. You will get that warning every time you try to use the header function after you've already echo'ed stuff in your code. The code will have to be reorganized so that the header functions all come before any echo statements, then you should be fine.
  9. Jack, I'm not Larry, but I may be able to help. To help though, a little more context may be helpful. When you post the form data, is it posting to the same script you render the web page from or is it posting to a completely separate script? That will greatly affect how you display the posted data. Thanks.
  10. John, we talked about this in your last post, but you cannot do mathematical addition on strings. Whenever you do .value on a DOM form input, you are going to get a string back, even if it looks like a number. That will always be the case. And when you start trying to do fancy math with strings, you'll almost always end up with NaN (or not-a-number). NaN is not a syntax error, that's a logic error in that you're trying to do number math with strings. Please fix that problem and you should be okay.
  11. Your if condition says, "If the number of hours worked is less than 80 and less than 100, then do something." I think that's your problem. Anything under 100 hours will net you the same result every time.
  12. Speaking in high-level generalities, I think there are two parts to this: Identifying the events that will cause notifications to be created; and Deciding how to display notifications to the users. An example of #1 might be creating a notification for a topic creator every time someone posts something in one of their topics. For example, you might create a notification with the ID of the person who posted in the topic and then the ID of the topic creator, who will get the notification. You can then decide how you want to notify the topic creator. Do you want to send them an email? Do you want to do what Stack Overflow does and have an icon at the top of the site? Do you want both? If you go with the icon approach, then the simple thing to do is to do a check for unread notifications directed at a particular user every time a user loads a page on the site. You could display the number of unread notifications or something, and once they read the notifications, then the number goes down. That's the basic gist. If you want to go into more detail, then we can, but hopefully that's a good start.
  13. Here's a good starting point: https://www.w3schools.com/html/html5_geolocation.asp You have to do this in JS though, not PHP, and if the browser doesn't support navigator.geolocation, then you have to fall back on some PHP alternative, which is up to you to decide. Please note that the Geolocation API is built into regular JS, and it's separate from the Google Maps API, which is provided by Google. However, if you use the Geolocation API to get the user's current location, then you can feed the acquired coordinates into the Google Maps API from there. Make sense?
  14. John B, glad you got it working. The only thing I will say in response as a critique is that I think that things like the following are a bit difficult to understand: +regularPay+ +overtimePay People familiar with JS will know that +numInStrFormat will convert a String number to a Number number, but it does make the code a bit difficult to understand at first glance. In general, the easier code is to read, the better. All the same, glad you got it working, and it seems like you learned a lot along the way, which is great.
×
×
  • Create New...