#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    13
    Rep Power
    0

    Select a product info from DB base on a string


    Hello,

    I see in many eCommerce links something like:

    /laptops/acer-aspire-e1-571G/

    So to show the product detail of the Acer the select is made by this string in DB "acer-aspire-e1-571G" ?

    Thank you.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    153
    Rep Power
    5
    More than likely, yes.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,026
    Rep Power
    377
    its a trick called url-rewriting internally the page might be somepage.php?cat=laptop&model=acer...
  6. #4
  7. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4124
    Building on what paul said, the product title might be

    Acer Aspire E1 571G

    When you make the link you replace a space with a -, then when reading you replace the - with a space. There are edge cases where a product might contain a - in its title, and these will need to be managed

    Whatever URL re rewiting is done when the request comes in, you'll get "laptops" in one variable (maybe $categoty) and "acer-aspire-e1-571G" in another (maybe $product). you then build a SQL query (safely) containing the appropriate variables
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    13
    Rep Power
    0
    So this string "acer-aspire-e1-571G" needs to be unique in the mysql table column. When you want the info for that product the search will be made in that column where are unique strings.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,026
    Rep Power
    377
    if you look at forums.devshed you will see (as an example)

    http://forums.devshed.com/php-development-(id)/select-a-product-info-from-db-base-on-a-string-(id).html

    you will see two IDs here.. this is ONE way.. the url contains both user friendly text and ID which is being used to query the database.

    as for your question, it probably needs to be unique BUT there is always going to be ONE Model as far as I am aware.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    13
    Rep Power
    0
    In the example that you given to me I understand that the search is made by ID.

    I ask this because as far I know searching a table by ID is much faster than search by string.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    153
    Rep Power
    5
    Originally Posted by raduenea
    In the example that you given to me I understand that the search is made by ID.

    I ask this because as far I know searching a table by ID is much faster than search by string.
    It's most likely faster in most databases to search by a number or fixed-length character string than by a regular variable-length string; but for a properly indexed database on reasonable hardware with a reasonable amount of data the difference is probably not significant.

    What you can be sure of is that whatever is being used to look up the data, it's contained within that URL, since that's pretty much all the server has to go on.
  16. #9
  17. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    I ask this because as far I know searching a table by ID is much faster than search by string.
    This sentence assumes that IDs are not strings. Using an auto-increment field as the primary key is actually considered incorrect in certain circles. The ID is metadata and unnecessary. if all your strings are unique (like these product titles), make the product title the primary key and all your problems are solved.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    13
    Rep Power
    0
    Thank you all.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    2
    mod_rewrite does the trick... Its very useful these days...
  22. #12
  23. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Originally Posted by The Alchemist
    mod_rewrite does the trick... Its very useful these days...
    Please read the entire thread before commenting. Incorrect and off-topic responses like these make us think you're a spammer.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo