PDA

View Full Version : HTML include??



Mr.Music
03-26-2005, 10:22 PM
Hello People,
When I was browsing on the web when i saw a site that had this in a url of it..
http://funprice.nl/info.html?sort=&id=2446&list=34&subgroep=55

now is my question:
How have they done this:S
is it include? or what

i need a explanation.
Because i wanna learn it too.
it looks cool:)

thnx in advance.
MrMusic

jscheuer1
03-27-2005, 03:21 AM
There are a number of ways this can be put into play. It basically means that a variable 'sort' is being passed to the page with a value of '&id=2446&list=34&subgroep=55' for some purpose defined by code on or linked to that page. I've done this to tell a slide show displayed in the center of a frames page where to start depending upon which image was clicked. In that case I just passed the variable directly in the href, something like:

<a href="ss.html?slide=12"><img src=thumb_12.jpg></a>
Catching the variable in the called page and doing something with it is a little more complicated.

mwinter
03-27-2005, 11:16 AM
It basically means that a variable 'sort' is being passed to the page with a value of '&id=2446&list=34&subgroep=55' for some purpose defined by code on or linked to that page.Not quite. Were that to be true, the ampersands (&) would have to be encoded as %26. The key sort has no value (or an empty value), and the others have values indicated after the equals (=) symbols.

Passing data through the query string (all text after a question mark in a URL) is typical of SELECT (retrieval) database queries, and other idempotent operations.

Mike

Mr.Music
03-27-2005, 08:08 PM
can one of you make a sample of it.
one page or something?
so i can look at the script.
would be cool
tia

jscheuer1
03-27-2005, 08:54 PM
This is the sending page (call it send.htm):
<html>
<head>
<title>javascript variable passing - page 1</title>
</head>
<a href="ss.html?var1=33">Send Variable</a>
</form>
</body>
</html> This is the receiving page (call it ss.html):
<html>
<head>
<title>javascript variable passing - page 2</title>
</head>
<body>
<form name="recieve">
<input type="hidden" name="var1">
</form>
<script language="javascript">
var locate = window.location;
document.recieve.var1.value = locate;
var text = document.recieve.var1.value;
function delineate(str) {
theleft = str.indexOf("=") + 1;
theright = str.indexOf("&");
return(str.substring(theleft, str.length));
}
document.write("var1 is " +delineate(text));
</script>
</body>
</html>

Mr.Music
03-29-2005, 05:37 AM
oh its javascript?.



is it also possible to include header and footer like it is possible in php?

jscheuer1
03-29-2005, 06:35 AM
What I wrote above is JavaScript. PHP (I'm not real familiar with the workings of PHP other than intermediate configuration of their list program) uses a similar scheme to pass user id and such but I've never seen it used to pass more than short variables. Maybe I wasn't paying attention. I think the header and footers in PHP are passed via includes using templates. I suppose you could use the scheme I outlined above to pass data in a variable that would then be written via script in the called page as a header or footer or anywhere in the page. That's a neat idea, not sure if it will work though.

mwinter
03-29-2005, 01:58 PM
oh its javascript?.Client-side scripts are easier to use for demos, but it is server-side scripts that use the query string 99% of the time.


is it also possible to include header and footer like it is possible in php?In PHP 4.1.0 and later, name/value pairs are accessible from the $_GET superglobal array[1]. For example,


<?php echo $_GET['id']; ?>would print 2446 with the URL parameters you posted at the start of this thread. Once you have these values, you can do anything you like: use them in database queries, use them to conditionally include other files. Whatever takes your fancy.

If you're looking to do something in particular, please be specific. If it's server-side, it might be better to take this to one of the other forums.


PHP [...] uses a similar scheme to pass user id and such but I've never seen it used to pass more than short variables.It's not a limitation of PHP, but a recommended limit to use of the query string itself. Some user agents don't handle long URLs well (some IE versions in particular) so it's best to only provide small bits of key information. Moreover, as people might bookmark the complete URL, or it might appear in the referrer logs of other servers, it's not good to use the query string for some things.


I think the header and footers in PHP are passed via includes using templates.Well, what headers and footers are we talking about here? Are you seeing something in this thread that I'm not?


I suppose you could use the scheme I outlined above to pass data in a variable that would then be written via script in the called page as a header or footer or anywhere in the page. That's a neat idea, not sure if it will work though.Of course you can. Generally you wouldn't dump data from the query string straight into the output for a document, but you would use it to look-up other bits of data on the server.

Mike


[1] In prior versions, you can use $HTTP_GET_VARS but that array isn't a superglobal.

Mr.Music
03-30-2005, 02:25 PM
Thnx for the info. i will try it out :)