Dynamic Links?

totalmockery

New Member
Messages
27
Reaction score
1
Points
0
Hi there,

I'm not 100% sure what to call this, I think it's Dynamic Links.
I want to know how to create links that produce urls like this:

http://www.example.com/news/?subtopic=news

For the life of me, and google, I can't figure this out. Mainly because I don't know what the technical term is for it.

Any help is greatly appreciated.


Cheers,

Joel
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
A dynamic link is one that is created as a result of the original url + a dynamic element, such as the addition of an id number.

For instance, you may have a standard url link such as http://www.yoursite.com/mypersonal details.php

The trouble is that if "someone" is logged in and you follow that link, the mypersonaldetails page has no idea who it is meant to look for.

Sooo.. dynamics.. the following is an example created in php.

Example for http://www.yoursite.com/mypersonaldetails.php?id=345

Create a recordset of users on a page you are linking from.

Create dynamic repeating table on the same page (do..while)

In each loop of $row, add the following..

PHP:
<a href="mypersonaldetails.php?id=<?php echo $row_userrecordset['id'];?>">link text</a>

This link is built in two parts - the first part which remains static. The you add "?" which allows the addition of a second identifier or any variable for that matter. The you specify what variable to send.. the "id=" part. Then generate the id created on that row - which is echo'd in php from the recordset.

When you click on this link.. it is dynamic and will carry the id to the next oage, where you capture that same variable and use it to create a new recordset on the new page.

i.e.

PHP:
<?php 
$new_id=$_GET['id'];
?>

This piece of code will obtain the variable from the url ($_GET) and assign it to the new variable ($new_id).

You can pass any number of variables in one url. Commonly, the current page is passed as a variable so that the new page can re-direct to the previous one.

Hope this explains a bit. :S
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Freecrm shows you how to do what you want, but if you want to know what you're doing, read on. The portion of the URI after the question mark is called a "query string". The elements of a query string are usually "field-value pairs" of the form "field=value" or just field names with no value, but they could have any format you wish. Of course, if you're using an ad hoc format, you're basically sending field names that you'll have to parse to get the data in the format you want. When you're dealing with a query string of the traditional field-value pairs, the pairs are also called "URL parameters". Note the difference between a query string and URL parameters: the URL parameters are the result of parsing the query string.

More generally, what you're dealing with is termed "form input" or "user input". This comes up in the very important directive "always sanitize user input" ([2]). I don't know how much you know about HTTP, but there are two methods HTTP methods that can send user input: GET and POST. Each uses a different technique to transmit user input, but any script you write to process the data won't see much difference. The GET request transmits input using the query string in a URL. POST is used by forms (though they can also use GET), hence the term "form input". The two methods are also the origin of the names for $_GET and $_POST in PHP.
 
Top