dzwestwindsor Posted July 29, 2010 Share Posted July 29, 2010 Hello! If you search Google, you'll notice the URL: http://www.google.com/webhp?hl=en#hl=en&source=hp&q=php+freaks&aq=f&aqi=g10&aql=&oq=&gs_rfai=CtdaTdtdRTNnPD5HuzASZtMWiCgAAAKoEBU_Q0ZT5&pbx=1&fp=19d754eee0b4f223 You can copy that URL anywhere you like... and the user will still see the same results. So basically the URL dynamically does an action, and accesses the database. How on do I make a URL like this? Meaning when you change the URL parameter values, it request a slightly different database query? Does that make sense? Similarly with NexTag.com: http://www.nextag.com/serv/main/buyer/ProductCompare.jsp?search=camera&page=0&node=500001&psort=%2FDigital-Cameras--zzcameraz500001zB6z5---html&zipcode=&cptitle=657166355&cptitle=656751324&cptitle=620051906&cptitle=705150048 That was a Dynamically made URL (I selected from check boxes which products to compare) and it makes that URL so anyone can see those products. Any ideas on how to do this? More examples on the URL: http://www.cars.com/go/compare/modelCompare.jsp?myids=9721,11439 (i select the cars, it generates that URL. Notice the IDs 9721,11439) Quote Link to comment https://forums.phpfreaks.com/topic/209265-dynamic-urls/ Share on other sites More sharing options...
Bisa Posted July 29, 2010 Share Posted July 29, 2010 If you wonder how to get values from the url into the php script (and subsequently into the db query) you might just be looking for $_GET[] Quote Link to comment https://forums.phpfreaks.com/topic/209265-dynamic-urls/#findComment-1092751 Share on other sites More sharing options...
acefirefighter Posted July 29, 2010 Share Posted July 29, 2010 You would use the $_GET[] global. I will use a simplified google.com URL searching for "hello world" as an example. like I said I have simplified the URL and removed all of the information Google uses for it's layouts. note the part of the URL that is "q=" we are going to take the search terms from after that "hello+world". http://www.google.com/#hl=en&source=hp&q=hello+world // get the serch tearms from the URL with $_GET[] $searchterms = $_GET['q']; // take the search terms and insert them into the database query $query = "SELECT * FROM database WHERE something = '$searchterms'"; // database connection credentials $dbc = mysqli_connect('databaseHost, username, password, databaseName'); // run the database query $results = mysqli_connect($dbc, $query); I think that is right there may be some errors but I think it gets the point across. Quote Link to comment https://forums.phpfreaks.com/topic/209265-dynamic-urls/#findComment-1092777 Share on other sites More sharing options...
dzwestwindsor Posted July 29, 2010 Author Share Posted July 29, 2010 SUPERB SUPERB SUPERB You are great. Thank you, I got it working. :D :D :D Quote Link to comment https://forums.phpfreaks.com/topic/209265-dynamic-urls/#findComment-1092782 Share on other sites More sharing options...
acefirefighter Posted July 29, 2010 Share Posted July 29, 2010 Not a problem. Glad I could help. Mark this as solved if you would. it is down, I believe in the lower left hand corner of the page. Keep in mind that there is a lot more than can be done with the search terms. In the example you are limited to an exact match in your database. Quote Link to comment https://forums.phpfreaks.com/topic/209265-dynamic-urls/#findComment-1092786 Share on other sites More sharing options...
dzwestwindsor Posted July 29, 2010 Author Share Posted July 29, 2010 right I understand, but I'm just doing drop down menus, so the queries will be right on! Thanks again (marked solved) Quote Link to comment https://forums.phpfreaks.com/topic/209265-dynamic-urls/#findComment-1092806 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.