tags:

views:

48

answers:

4

Hi,

it is probably a dummy question, but... I generate HTML document from a database. Some parts are generated as hyperlinks, which should contain additional information: Table name, ID of table row etc... When user click on it, the program should extract and decode this information and generate another part of database as HTML document.

I can not figure out what is the best way to do it...

can anybody help?

thanx

A: 

You should add a new attributes.

<a href="#" name='link' database='name of db' table_name= "test_table">TEst</a>
Oyeme
I don't believe these are actual anchor attributes + how would they be retrieved?
m.edmondson
If the data has to be encoded in the markup itself, going with the new HTML5 data attributes is the far better approach, IMO: http://html5doctor.com/html5-custom-data-attributes/But I doubt that's what the author was looking for.
Horst Gutmann
to retrieve -an attributes you should use java script.(jquery)
Oyeme
The user specifies he'll be using the information to get the data from a database, javascript cannot do this
m.edmondson
you should not forget that html5 is not supported by all browsers yet. And will mostly not be supported the same way
krike
+1 This is actually a good answer, and a technique used frequently. jQuery is very good at retrieving this data and even identifying elements based on it. I would recommend using the following format: data-attributeName="attributeVaue" as this will be HTML5 valid when it is supported. It will still work in earlier browsers, just not pass html validation.
Daniel Dyson
A: 

I don't fully understand but the best way to transfer data across web pages is by using a form and transfering it as a $_GET[''] or $_POST[''] in PHP. Other than that if the hyperlink is just containing some variables you can make it http://www.something.com/getnewdatabase.php?Var1=Database1&amp;Var2=TableRowID then on the other side pick them up with PHP as $_GET[''] variables. I can't think of a way to do it with purely HTML though, hope this helped

Harold
+1  A: 

the best way to do this is with a querystrings

you would have to construct a link something like:

http://mysite.com/generate.php?table="name"&amp;id=5

You link them to your page that generates the html pages and there you would then be able to get those values, store it in a variable and the run a new query and generate a new html page.

$table = $_GET['table'];
$id = $_GET['id'];
krike
+2  A: 

What you're after is the querystring. Take a look at Google, usually its http://www.google.co.uk but after you've done a search the URL is http://www.google.co.uk/search?q=mysearchterm Can you see that mysearchterm has been added to the link?

Give this a try, the hyperlink has actually sent "mysearchterm" to Google via the querystring. You can pass more than one variable like this by separating with an &. So you would pass the Table name, ID of table row in the link like this.

Take a look here to get you started, but be aware that anyone can edit these values so don't pass anything secure.

m.edmondson
thank you very much for navigating me in right direction. I made my research myself based on your recommendation, so I can confirm, that this is a common practice, furthermore it is supported by .net framework... I send special thanks @krike, @Harold
lyborko