Forum Moderators: mack

Message Too Old, No Replies

Query Strings

What are they and how do they work?

         

Gary_Numan

7:51 am on Oct 27, 2005 (gmt 0)

10+ Year Member



I was reading something recently about using query strings in order to increase page numbers on a site.

It sounded very interesting but most of it was a bit too technical and went over my head. It is something to do with adding a? to the url.

How is it done, what does it do, how does it help?

Could someone please explain it to me in basic terms?

Thanks

Gary

raimondious

5:44 pm on Oct 27, 2005 (gmt 0)

10+ Year Member



A query string is information appended to the end of a URL that can be parsed by a language as (or after) the page is being rendered.

An example is

[yoursite.com...]

if you wanted more than one parameter, you would separate them with &'s like so:

[yoursite.com...]

If you are using PHP, for instance, this information can be used to assign a value to a variable ( $page= $_GETVARS['pagenum'] ).

You can use SSI to display query info with <!--#echo $QUERY_STRING -->, I believe.

If you wanted to use JavaScript, it is a bit more complicated, but probably more along the lines of what you're looking for. You might find it useful to read this [javascript.about.com], which is one of the first things to come up when I Google 'javascript query string'.

Does that help?

Gary_Numan

11:34 am on Nov 3, 2005 (gmt 0)

10+ Year Member



Thanks,

The link helped a lot, but your message was over my head I am afraid :)

This is the 'New to Web Development' section remember.

;)

Cheers

Gary

g1smd

8:30 pm on Nov 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Many catalogue websites run with all the product information in a database.

The webserver runs a script that gets information from the database, assembles a page of HTML code containing the content and then sends it to the browser.

The clever bit is that the website only has one "page" and the different content for the page is asked for by adding parameters to the end of the page name.

So, www.shirts.com/buy.a.shirt.php will show you the main navigation and choices for the site (no parameters were supplied with the URL) and www.shirts.com/buy.a.shirt.php?colour=blue&size=16&logo=34 will cause the script to get from the database the text and images for the product that is a shirt that is blue, size 16, and has a particular logo on the pocket.

What you have to beware of is always keeping the parameters in the same order in each link that you use on your site.

You can hide the mechanics of the query string by using a URL rewrite. This post appears at /forum48/2533.html but in the background its true URL is probably something like forum.php?forum=48&discussion=2533.

You can see that in effect for the URL in your browser address bar when you are writing a reply: /edpost.cgi?action=reply&forum=48&discussion=2533 for example.

Gary_Numan

10:29 pm on Nov 5, 2005 (gmt 0)

10+ Year Member



Thanks for the information.

Always nice to see someone taking time out to help.

Much appreciated.

Gary

coburn

10:56 am on Nov 12, 2005 (gmt 0)

10+ Year Member



Hi Gary,

If you want to rank well in the SE's, I would suggest you use a rewrite. So instead of showing something like "id=5?" or "?pagenum=6" in the URL, use apache or IISRewrite to change this URL into a more conventional one (without a "?"). If you choose your replacement word/phrase carefully, you can score a few extra points by targetting your keyword phrase (kw) to the page being delivered (so if you've optimised the page for "orange toes", and your url shows: www.yourdomain.com/orange-toes/ - you will be doing your page a favour wrt ranking.

It's worth knowing the difference between dynamic pages and static pages. Static pages are generally FTP'ed onto and from the server. They appear on the site as they appear to you on DW (dreamweaver) or FP (Frontpage). Dynamic pages (as discussed by g1smd) on the other hand cannot be uploaded via FTP and cannot be viewed fully in DW or FP. The page contents are pulled from a database, and often from other pages as well (like a shared footer, header, menu navs and other common elements). As a visitor, unless they're showing the "?" in the URL, you won't know whether it was served up dynamically or not - and neither will the SE.

I would advise that you stick to static FTP'able pages if your site is small. The larger you get, and the more similar your pages are (large sections of articles or products for example) the more onerous it can be to change, upload and download FTP pages, and the better therefore to switch to dynamic pages.

Hope this helps,
Coburn