Jump to content
Larry Ullman's Book Forums

Larry

Administrators
  • Posts

    5413
  • Joined

  • Last visited

  • Days Won

    155

Everything posted by Larry

  1. In my daily programming, I don't pass variables by reference often. I normally think of it as being more useful in OOP (where sometimes you need to work with a complex object) and sometimes I've used it when I'm being lazy. But as a concrete example, if you have an array that needs to be manipulated by a function, it's easier to pass that array by reference so that you don't have to return the array. The array_walk() function does this: http://us2.php.net/manual/en/function.array-walk.php If you look at the first argument in the function definition, you'll see the array to be walked over is received by array_walk() by reference. Passing by reference can also have a performance benefit for very large sets of data, as passing by reference doesn't require the creation of a second data set (i.e., a doubling of the memory required).
  2. Hello Roger, Sorry for the confusion. From looking at your code, it seems that you've got one script that has the form and retrieves the data from the database. Your one script also has all the necessary HTML, but also has some JavaScript as if it were an Ajax version. Using an Ajax model, one script would have the form (it could be an HTML page, without any PHP). The form calls a JavaScript function that performs an Ajax request of the server. That file on the server only returns the data, perhaps in JSON format. The server-side script does not have any HTML in it (as in stores_json.php). And to clarify, this chapter DOES have the complete code for demonstrating Ajax. What it doesn't have is the non-Ajax version, to be used as a fall-back should the user's browser not support JavaScript (which is uncommon these days). And that non-Ajax version is something any intermediate level PHP programmer could easily create. So the find_stores.php script, which is the non-Ajax version not included in the book, would be a lot like your code, but without the unnecessary JavaScript, JSON, and so forth. Again, in simple terms: Ajax process: HTML form -> submission -> call JavaScript function -> JavaScript function calls server script -> server script returns data -> another JavaScript function handles the data and updates the HTML page Non-Ajax process: HTML form -> submission -> server script creates entire HTML page, including displaying data based upon form submission Let me know if that's still not clear or if I'm incorrect about your script.
  3. Thanks for the nice words on the books. As for this question, the first thing you'd want to decide is whether to base the prices of things on one price, and then convert to other prices based upon a flexible conversion rate, or to set the prices in multiple currencies at once. Then it's just a matter of having a button or link or form element that the user clicks to select a currency. Store that in a cookie or session, and use that to determine what prices to display.
  4. Thanks for the questions, Jonathon. It's a valid line of thought. And thanks to HartleySan for the answers, which I totally agree with. First, HTML 5 will impact Flash, I suspect, but not be its downfall. It will be years before HTML 5 will be officially released, let alone reliably supported. Plus, more than anything, there's no one right tool. I think the arguments for Flex-based Flash content over JavaScript-based rich content are these: - Speed of development - Reliability across all platforms If a person can run Flash, the Flash will work the same (aside from performance issues on older machines, depending) everywhere. And Adobe would say that the Flash plug-in is installed on 99.9% of all computers. Of course, Flash content can't run on iOS devices, which is a concern. You can, of course, make JavaScript-based content run reliably on all browsers, it just takes more work. Frameworks such as jQuery simplify this process, too. The speed of development is an obvious, and big, benefit, especially the more complicated a project is. Flex 4.5 and Flash Builder 4.5 now supports mobile devices better, so you can create apps that will run (via AIR) on iOS, Android, and Blackberry Tablet devices easily. I'm going to play with that more this summer, but that's a crazy big benefit to me. As for myself, if I need to add a little bit of dynamic functionality to a Web page, I use JavaScript. If I need to add a lot of dynamic functionality, or make something closer to a Web-based app, I use Flex. If I'm making desktop applications that run through AIR, I use Flex (even though I can use JavaScript for that, in fact wrote a book on that subject). So really it's a matter of scale to me. Certainly complex applications can be created in JavaScript, but it's just simpler and easier to use Flex at some point.
  5. Yes, that's exactly correct, Rick. Thanks and kudos! MySQL executes queries through a series of steps, not in sequential order through the query.
  6. Glad it's working and thanks for letting us know. For future reference, with a question like this, a lot more details would be required to help solve the problem. Just an FYI.
  7. Okay, then. To me, the code you posted does not demonstrate Ajax at all, but perhaps I'm missing something. The important thing is that you're satisfied with where you're at.
  8. Part of the problem could be the spaces around the equals signs. Part of the problem could be the use of single quotes instead of double quotes. It also could be the use of "unchecked". I've never personally seen or used checked="unchecked", although maybe that is valid.
  9. My apologies. I totally overlooked the use of the stored procedure return_distance() that's in the SELECT query. Yes, for that you need EXECUTE privileges. Kudos for figuring it out and thanks for posting your solution.
  10. That would do it. Glad you figured it out and thanks for letting us know.
  11. Antonio is correct, although you could use JavaScript to provide feedback and limitations as the user types.
  12. Hello Matt, Glad you found it. Sometimes I forget what I've written about where. Actually, I would put the proxy script in the main directory because it IS a standalone script. It's never included by any other file. Also, since users will be directly accessing the proxy script, it's best not to tip them off to the existence of the includes directory (not that that's a huge deal).
  13. Hello Terry, That's a good point about having multiple hosts, especially as your business grows. My handful of (non-client) projects are all with ServInt, because I have a VPS account. If I ever felt like I outgrew one VPS account, a smart choice would be to get another VPS account with another host. That way I could also provide some redundancy.
  14. Thanks for the nice words on the books. I think you're a bit confused by what's going on here. First of all, MySQL users don't have privileges to "mysqli functions". Second, this query is just a SELECT query, so the MySQL user that's trying to execute the query only needs SELECT privileges.
  15. Thanks for sharing that code, but I'm confused by what you're wanting to do. The book has an Ajax version of stores, I thought you wanted to create the non-Ajax version. I'm not clear as to what you're looking for, or what the code you've just posted is supposed to do.
  16. No need to apologize, Matt. It's fine. Let me know if you have questions or problems once you get around to applying what I've suggested above and in those other places. As for that code, for the life of me I can't think why you'd need to apply the error suppression operator to the round() function! I think he used error suppression in lieu of conditions and proper programming.
  17. I don't really have the time right now to go through that code and make detailed comments and improvements. I have to spend my time not dropping balls... I think it's best to place uploaded files outside of the Web directory, but rather than waste time in the second example showing you how to do something I already showed you how to do, I thought it'd be better to use the precious book space to teach new ideas. I think you're over-thinking this and are perhaps just confused about what's happening. Using the PDF proxy script as an image proxy script would be a stunningly simple change to make. You say "images are a different story", but they're not. It's exactly the same idea and the particulars would only be slightly different. For example, the PDFs are linked using . The user clicks on that link, which executes the view_pdf.php script. That script sends the PDF file. To do this same thing for images, you'd first change the HTML to: The view_image.php script would do the necessary validation, send the content-type header appropriate to the image type, and then send the image to the browser. You need to change the validation and point to the right file directory, but, really, changing the one line (the content-type header) is all that's required. Also, there's absolutely no JavaScript involved there. I'm not sure what you mean by "streamed to a popup window using JavaScript", but that's not happening. Again, I don't really have time to go around analyzing random bits of code found on the Internet. Thanks for the nice words and for the recommendations. It is appreciated. But, again, I think you're totally over-thinking this. It's a much more simple change than you're making it out to be. And, of course, if you have problems or don't like using a proxy script for uploaded images, then don't. I also wrote a detailed discussion of proxy scripts in one of my newsletters a couple of months back. And I wrote an image proxy script in one or more of my books (I know it's in the PHP & MySQL book).
  18. Matt, I would think twice before jumping from $62/year to $600/year. You seem to be happy with what you have now, and it seems to fit your site and budget, so please don't go making drastic changes and spending lots of money just because of what I wrote. At the end of the day, you have to do what's right for you. Abigail, thanks for sharing. It's insane that your Web host won't release your domain name to you. That's just a way of forcing you to stay with them. I don't think I've written about this (or much), but it's important to manage your own domains through a registrar. It may end up costing an extra $15/year that way, but the freedom is worth it.
  19. I wouldn't think of this as being a security solution. But if you want/need to resize uploaded images, then you should do this. As for the particular code, the original creator is way too dependent upon the error suppression operator! I've never seen code quite like that before!
  20. Sorry, that should refer to stores.html, not stores.php. What I'm saying is that the book demonstrates how to find and display the stores listing using Ajax (in using stores.html and the JavaScript). For fallback reliability, you could create find_stores.php, which handles the form submission should the user's browser not support JavaScript. I didn't create find_stores.php in the book because it's a very simple script that any PHP programmer should be able to write (and it's standard PHP, not Ajax). If you're having any problems writing your own find_stores.php, let us know. Sorry for the confusion.
  21. Yes, that's right. The Visual QuickStart Guide is a more basic book than the Visual QuickPro. Thanks for the nice words on the book and for the interest in reading more of my books!
  22. Of course. I've been using ServInt for three years or so now and I'm very pleased. They only do dedicated and VPS hosting, though, so the cheapest plan is $50/month (which is what I'm using).
  23. No, it's not the htaccess that's causing the problem, it's the paths to the images in the HTML and CSS. By default (i.e., in the book and the code), the paths start with /, indicating that the images and CSS and such are in the root directory. Since you've put your files in a subdirectory, you need to change references to /something to /ex2/html/something. You'll need to do this to the HTML for the links as well.
×
×
  • Create New...