Jump to content

Dynamic URL's???


dzwestwindsor

Recommended Posts

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)

 

Link to comment
https://forums.phpfreaks.com/topic/209265-dynamic-urls/
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/209265-dynamic-urls/#findComment-1092777
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/209265-dynamic-urls/#findComment-1092786
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.