Jump to content
Larry Ullman's Book Forums

HartleySan

Members
  • Posts

    3047
  • Joined

  • Last visited

  • Days Won

    243

Posts posted by HartleySan

  1. Your post has left me confused as to whether you want more advice or not.

     

    When you grab all the subjects from the database, grab the IDs as well, and then set those to each of the links. For example:

     

    echo '<a href="display_subjects.php?id=' . $row['id'] . '">' . $row['subject_title'] . '</a>\n';

     

    Something like that should suffice. You can then use the $_GET superglobal from display_subject.php to grab the appropriate subject and content from the database.

     

    Cool?

    • Upvote 1
  2. Doesn't Larry do something like this for his user registration script in the PHP 6 & MySQL 5 book? I think he sets a default value when a user is registered, and only changes that value once a user confirms their registration from their email account.

     

    I guess the point is, I think null fields return NULL from MySQL database queries, in which case, checking the PHP.net manual should net you a way of testing for NULL, but the "easier" solution would be to set a default value, (which isn't NULL and) which signifies that a gallery has not been created yet, and just test for that value. Naturally, you'd want the value to be something that could never be set for a gallery, which is simple enough.

     

    Also, Jonathon, congrats on post #200.

    • Upvote 1
  3. Depending on how far you want to take it, doing that might be difficult. If you'll notice, the URL is not composed of the standard script-name.php?name=value&name=value syntax.

     

    I can't recall exactly (hoping for Larry to step in), but I believe he covers how to do this at the beginning of the second example site in his e-commerce book. Basically, you need to use an .htaccess file, etc. to convert the format of the URL.

     

    I think it would be best to start out with the standard format used for the GET method, and once you have that working, then add this additional later on. In the end, the functionality is the same. The only difference is that the URL becomes slightly more "readable" for humans.

    • Upvote 1
  4. Thanks for your response. I definitely recommend learning more about Ajax. While PHP will always be a solid backbone for sites, more and more, JavaScript is taking center stage these days.

     

    If I were you, I'd probably just make two database queries, and test it out like that for a while, seeing how much of a load it actually makes on your server. If the load is unacceptable, then you can start considering alternatives.

     

    It just crossed my mind that maybe you could use an OR statement in your query. For example, WHERE something OR something-else. Of course, that might cause some overlap issues.

     

    The more I think about this, if the query gets too difficult, making two simple queries will work better.

     

    This is quite often the case with regexes as well. Quite often, two simple regexes are better and more efficient than one complicated regex that accomplishes the same thing.

  5. Good points, chop. Thanks. While I consider myself more an intermediate "PHP guy" by now, it was only a few years ago when I was a beginner, and I remember the feelings that chop expressed well.

     

    The best thing to do is follow along with the book, and play with the code as you go along, in order to better understand how the different parts work. And if you find yourself completely stuck and/or not understanding something conceptually, come here and ask.

  6. bahaa, as Jonathon said, it's hard to imagine exactly what's wrong. As you noted in the title of your post though, I imagine that you're not properly creating the links to the subjects.

     

    This sounds like a message board-type thing. Anyway, I imagine you have a separate script used for displaying the content of a subject, right? If that's the case, in each of the links, you'll need to call that script, and then send additional information in the URL that the GET method can use to retrieve the proper subject and its content/comments.

     

    Well, hope that helps.

    • Upvote 1
  7. I found a post that is a couple of years old, but it seems to state that phpMyAdmin cannot handle calling stored procedures. The following is the link to that post:

     

    http://tycoontalk.freelancer.com/the-database-forum/117270-phpmyadmin-and-procedures.html

     

    After Googling it a bit, it seems like all sites say the same thing: Stored procedures are not supported. If you want to test them, you more or less just need to type out the actual query with some test data.

     

    Edit: Stored procedures can be created and edited, but not called from phpMyAdmin.

     

    Sorry I can't be of more help, but that's pretty much it.

    • Upvote 1
  8. Yes, I better understand what you're asking for now. Thank you for explaining that.

     

    I suppose the best answer to your question would be to try and reduce the filters and conditions you are using to limit the data. I feel like two relatively unrestricted database calls will be less of a load on your server than one call that has a ton of limiting factors built in (although I'm not sure about that).

     

    Either way, I think there are a couple of things you can do. I don't know exactly how you're handling the different permission levels, but maybe you could always return the 20 most recent records, as you'll be guaranteed to have 5 within those 20 that match your filters. From there, you could use JavaScript to filter the results. Because JavaScript runs on the client side, not the server side, server resources would not be taken up filtering the results. Naturally, that would require Ajax, but it's a viable option, I think.

     

    Similar to the above, if you could use a database call to determine where the 5th record that meets your conditions is, you could simply retrieve all the records to that point (which shouldn't be too many), and then further limit them as necessary. Again, I'm not exactly sure what you want to do here.

     

    On a side note, I recently read an article about Facebook's technique for loading pages so quickly, and it involves using a custom object called BigPipe to make multiple asynchronous Ajax calls to a database, so that as each call is returned, it can load a small part of the page without having to wait for the rest of the database calls to finish. Likewise, you could set up two different Ajax calls to your database, and just load each one as they are returned.

     

    Any thoughts, opinions or objections would be appreciated. Thanks.

  9. kbs, I agree with Jonathon. Certainly, I understand the pressure that a deadline can create, but ultimately, you're better to start at the beginning and learn things properly. And to that end (while I am admittedly somewhat bias), no one covers PHP and MySQL better than Larry. And to answer your other question, without a doubt, I think PHP/MySQL is the best way to go for your project.

     

    Also, like Jonathon said, go through the book slowly, and if you're confused about anything whatsoever, please ask on these forums. We will try to assist you as best as possible. As long as you're nice about it, there is no question too dumb.

     

    Anyway, good luck, and we're here to help you.

     

    Edit: Concerning XAMPP, you shouldn't be getting a port 80 error. If that's the case, then most likely, your environment is causing the problem, not XAMPP. Without knowing more about your environment though, it's impossible to comment on that.

    • Upvote 1
  10. I am a little unclear on what you're referring to, but if you're talking about dealing with XML data in MySQL, I found the following, which might be helpful:

     

    http://dev.mysql.com/tech-resources/articles/xml-in-mysql5.1-6.0.html

     

    I actually don't generally deal with XML data, as it can introduce a lot of overhead. Nevertheless, I suppose another option might be to store the XML data as a standard string in the database, and then use some sort of PHP library that can interpret that string data as XML data and perform appropriate DOM functions on it from there.

     

    Again, I'm not actually sure what you're asking for, nor do I have much experience with XML in PHP. Sorry.

    • Upvote 1
  11. Terry, I'll be honest, I'm a little confused about what you are asking, but here's how I'm interpreting your post:

     

    You have a bunch of data in a database that you want to paginate, but instead of having to make a new database call everytime you go to another page, you want to know if it's possible to make one database call at the beginning to get all the data, and then still achieve pagination. Is that correct?

     

    Well, I would appreciate some clarification on your part, but assuming that that is what you're asking, you can use Ajax to accomplish that. I think there are a variety of approaches, but what I'm thinking is that you make an Ajax query on page load, store all that data in an array of objects (as an example), and then limit the amount of data displayed on the screen via JavaScript. Since all your data would be stored in one JS variable (the array of objects), you could simply set up events to display different parts of the array data when another page link is clicked, etc.

     

    Anyway, sorry if I'm way off on what you're asking, but please let us know.

    • Upvote 1
  12. Yes, naming is a matter of convention, but the fields must be of the same type.

     

    From the MySQL home page:

     

    Corresponding columns in the foreign key and the referenced key must have similar internal data types inside InnoDB so that they can be compared without a type conversion. The size and sign of integer types must be the same. The length of string types need not be the same. For nonbinary (character) string columns, the character set and collation must be the same.

    (Source: http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html)

    • Upvote 1
  13. You may have already seen this page, but I found the following:

     

    http://www.tech-evangelist.com/2007/11/05/preventing-sql-injection-attack/

     

    Also, I find it hard to imagine a situation in which you don't know (or can't quickly determine) what version of PHP you're using, and you're concerned that the version might be so old that it does not support mysqli_real_escape_string.

     

    Is that a legimate concern? Well, all the same, I think you're on the right track.

     

    Edit: And one more good (and detailed) link for good measure:

     

    http://php.net/manual/en/security.database.sql-injection.php

    • Upvote 1
×
×
  • Create New...