SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 58 of 58
  1. #51
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    You shouldnt need more than 1 if(isset()) per -level of navigation-. (And probably less than that, even)

    While it's true that it will only take milliseconds (or less) to make the if call, you still shouldnt do more than is required.

  2. #52
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The trickiest bit I think will be adding navigation for all accessories for all products. Specifically this means if you are looking at a particular accessory for product 200 of 300 products then all accessories for product 200 will also feature in the navigation bar.

    Are you suggesting I should only be using one if(isset()) function for all these different products?? Is that possible? I can only think of using an isset function to determine what product is clicked and then provide the navigation links based on that but this would be an isset function for each product... how can fewer (or 1) isset functions achieve the same outcome??

    Matt.

  3. #53
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Without knowing the database structure this will be pure guesswork, but...
    PHP Code:
    if(isset($_GET['product']) { //I have cloicked on a product. This product's ID is being stored in that variable.
      
    $stuff =  $sql->query("SELECT somestuff FROM accessories WHERE productID = ".$sql->real_escape_string($_GET['product']));
    //This query will get the accessories associated with the product in question, no matter which product it is.
      
    while($row $stuff->fetch_array()) {
        
    //Output whatever here.
      
    }

    1 ISSET, every product covered.

  4. #54
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll try it out.

    Thanks.

    Matt.

  5. #55
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a problem with the line:

    $stuff = $sql->query("SELECT somestuff FROM accessories WHERE productID = ".$sql->real_escape_string($_GET['product']));

    It produces a fatal error which reads:

    "Fatal error: Call to a member function on a non-object in /home/content/..."

    I do not understand what the $sql means or does - maybe it is that which is producing this fatal error? Any ideas?

    Matt.

  6. #56
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    $sql in my code was a mysqli object. If you're using a mysql procedural call, it would look like
    $stuff = mysql_query("SELECT somestuff FROM accessories WHERE productID = ".mysql_real_escape_string($_GET['product']));

  7. #57
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    StarLion,

    Can you just briefly explain why you suggest using _real_escape_string for this part of the navigation and not the previous part of the navigation bar. Is there a very good reason? Or would you recommend I use _real_escape_string in the previous code you suggested too?

    All the best,

    Matt.

  8. #58
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    real_escape_string (or sanitization) should be used whenever you use user input in a database query. Always.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •