View Full Version : Query Strings
zangerbanger 06-12-2003, 01:48 AM Can somebody (ANYBODY) explain to me step by step how to make query strings work. I've been trying to do this for many weeks and even the most simple tutorials I found don't seem to work for me. If anybody can help, I'd greatly appreciate it :) .
freakEgurl 06-12-2003, 04:02 AM I'll try my best to explain .. Hopefully you'll understand.
ok, make your normal layout and stuff, just without the actual content part. just make a layout.
then, add where you want your content to appear, add
<?php
elseif ($x=="pageone") {
include ("pageone.inc");
}
elseif ($x=="") {
include ("gm.inc");
}
else {
echo "This link is invalid";
}
?>
You only need one layout file.
make .inc files with your content dont include the layout or anything else that part of the layout. They should be html files, but the an inc extention. name them how you want them to be named.
In your layout, paste that code above but modify it how you want it.
elseif ($x=="pageone") {
include ("pageone.inc");
}
how it works basically is(look at tiny peice of code above, when your url is yourdomain.com/layoufile.php?x=pageone, the code will include whatever is in pageone.inc wherever your php include code is.
to make your layout.php page have an include, use
elseif ($x=="") {
include ("gm.inc");
}
change gm.inc to whaever you names your .inc file.
else {
echo "This link is invalid";
}
is just a piece of code, to, when somebody types in an invalid url, like yourdomain.com/layout.php?x=nonexsitant page, it will displae this link is invalid.
you can have as many of
elseif ($x=="pageone") {
include ("pageone.inc");
}
as you want. They just need to have diffrent names. Dont forget the curly brackets though.
And, I hope thats understandable.
my site uses query stings, if you want my source file. email me *points at email button* ... I think an actual file will help.
zangerbanger 06-13-2003, 03:04 AM Wow! Thanks, you were tons of help :) .
freakEgurl 06-13-2003, 03:48 AM :D
designhazard 06-13-2003, 03:16 PM or, this code works with includes
<?
if ($page) {
require $page;
}else{
require("default.html");
}
?>
let say you named a page with the code above test.php and the other one with includes test2.php. so, you will do this: test.php?page=test2.php. you can remove the bolded text above the code if you don't want a default page.
zangerbanger 06-13-2003, 11:20 PM I'm a bit confused here. I'm trying the code that freakEgurl gave me and I don't know where to put it. Another one of my problems is that all my sites are coded up in PHP and by changing the filename to .inc, those sites no longer can function. Here is my entire index:
<?php
echo "<html>";
echo "<head>";
echo "<meta name=\"keywords\" content=\"zangerbanger, Jordan, Zhang, jordan, zhang, eternal, dreamer,
eternal-dreamer, personal site, tutorials, me, visitor, tutorials, miscellaneous\">";
echo "<meta name=\"description\" content=\"This is a personal site all about me. You'll learn loads of
*interesting* things but visiting my page.\">";
echo "<meta name=\"author\" content=\"Jordan Zhang\">";
echo "<title>Body And Soul: Version 2</title>";
echo "<link rel=\"stylesheet\" href=\"stylesheet.css\">";
include "javascript.txt";
echo "</head>";
echo "<body topmargin=\"0\" leftmargin=\"0\" bottommargin=\"0\" rightmargin=\"0\">";
echo "<img src=\"layout.png\" width=\"700\" height=\"500\" border=\"0\">";
echo "<div style=\"position:absolute; top:375px; left:10px; width:200px; z-index:1;\">";
include "sidebar.txt";
echo "</div>";
echo "<div style=\"position:absolute; top:105px; left:320px; width:340px; z-index:2;\">";
include "menu.txt";
echo "<form action=\"http://pub35.bravenet.com/emailfwd/senddata.php\" method=\"post\"
enctype=\"multipart/form-data\">";
echo "<input type=\"hidden\" name=\"usernum\" value=\"2941088165\" />";
echo "<input type=\"text\" name=\"name\" value=\"Name?\"> ";
echo "<input type=\"text\" name=\"ask\" value=\"Ask me a question!\"> ";
echo "<input type=\"submit\" value=\"Ask\"><input type=\"hidden\" name=\"subject\" value=\"Hey
Jordan!\">";
echo "</form>";
include "blog.txt";
echo "<p> </p>";
echo "</div>";
echo "</body>";
echo "</html>";
?>
freakish_dude_ 06-26-2006, 04:19 AM u dont name ure actual pages .inc
it means the content u want to be displayed there, eg: say u wanted to say hello on your content page
so in content.inc it would say hi
im VERY new to this, to be honest im not even sure what a query string is, but while i was reading a post had a link to this one, and im not sure if this is what i need.
my index is basicly a few includes, wich is great i no longer have to paste my layout code over and over.... but now i realized if i make the rest of my pages like that, i would have to make 2 pages for each link, one would be basicly the same as index except i would change the include for 'news', for the one that corresponds to the chosen link, for example 'contact me' and the other one would be basicly my contact information without the layout right?
so i'm guessing i need some sort of variable...thingy(this proves how much i know), so i dont have to repeat over and over the page with the includes; also i'd like to know if the code would go just where my links are or if a part of the code would go in the index too.
oh and i also saw another post:
http://www.lissaexplains.com/forum/showthread.php?t=15590
i think she wanted to do the same as me avoiding using frames or iframes.
well i tryed to be as clear as i could, any comments or sugestions will be greatly apreciated :purplecat
sputter 06-28-2006, 03:19 AM Here is a link which explains it pretty thoroughly
Dynamic Includes (http://codegrrl.com/!/tutorials/view/dynamic_includes/)
The only thing that seems to confuse people is this;
You have your index.php which will be the page with the code
A header.php with the top portion ofyour page before your content
A footer.php which finishes the page after your content
These will display your page template
Then you have a directory called pages this is where you put the content for all your pages
This works kind of like so
Say you have your content in news.php, put the news.php in the pages folder, then to call it up it would be index.php?news
You want an about me page? create about.php, put it in the pages folder and use index.php?about to call it up
sputter 06-28-2006, 07:08 PM No prob, glad I could help
Ixgraphix 07-27-2006, 07:09 PM I Have a Question.. do you HAVE to name your files inc, inorder for this to work?
sputter 07-27-2006, 08:05 PM I Have a Question.. do you HAVE to name your files inc, inorder for this to work?
No, in all actuality it's probably best if you shy away from inc as an extension. Most browsers will parse it as a text file, thus showing any coding you maybe using in that file. If you need the inc to keep things straight use filename.inc.php or just stick with filename.php. If it's just html, you can even just use an html page to include or even a text file. As long as you specify the file name in the code you should be fine.
|