Jump to content

Query string question


BrianM

Recommended Posts

How is it that you get one page, say index.php, to contain content for multiple pages. Like - index.php?mode=register or index.php?mode=edit ... that being an example, I hope somebody see's what I'm getting at here. But how does a page use $_GET[''] based on the contents of the query string to determine what part of a page to display if it's all on one page?

Link to comment
Share on other sites

when you use $_GET['variablename']  it retrieves the value for you from the URL.

so as in your example: the URL = index.php?mode=register


$a = $_GET['mode'];
//print($a);

 

Now you use that variable in a switch statement and use it to call your includes.

 

switch $a {

   case "register":
   include('register.php');
   break;
   
   case "edit":
   include('edit.php');
   break;
   
   case default:
   include('main.php');
   break;
   
}

 

you would setup all these pages to be the content of your site.

and put the above code at the top of your page.

 

Link to comment
Share on other sites

Instead of making a new topic I thought I would continue in this one.

 

I'm getting this error with the following code, and I don't see any problem with it, hopefully somebody else will.

 

Error: Parse error: parse error, expecting `'('' in C:\Program Files\Apache Group\Apache2\htdocs\timetech\install.php on line 110

 

Code:

<?php
mysql_close($mysql_connect) or die(mysql_error());
} else if { // this is line 110
	header("Location: install.php?mode=delete");
	}
?>

Link to comment
Share on other sites

if (isset($_GET['p'])){
        if (valalpha($_GET['p'],1,255) AND (file_exists("ing/". $_GET['p'] . ".php"))){include("ing/". $_GET['p'] . ".php");} else{include("ing/news.php");}
     } ELSE { include("ing/news.php"); }

 

im using this script for that...

Link to comment
Share on other sites

grimmier, your get example works, but I don't want it to keep the same page content up after a new query string is brought up, but instead take away what's there and just show the new include file without the old page... is this possible?

Link to comment
Share on other sites

yeah you can do that, just recall the page and change your variables witin the url. if you want to keep the same function for all of your pages.

 

i have some other examples of this floating around. but its 3:30am here now and i can't think straight anymore.

 

Link to comment
Share on other sites

I hear you there, I'm surprised I'm in the mood to learn anything at 2:45 am :|

 

Well I think I'm going to continue this tomorrow, going to hit the hay and call it a night.

 

Thanks for all your help! :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.