Jump to content

Recommended Posts

Ok so here's my scenario. I'm building a website, but I want to have a popup with information on it. I want to have the popup go to like...  popup.php?id=SOMETHING, where SOMETHING will be a number like..

popup.php?id=20 would go to something1.php

popup.php?id=21 would go to something2.php etc

 

Basically, so it shows as popup.php?id=21 instead of showing something2.php :/

 

I really don't know that much about it >.<

Link to comment
https://forums.phpfreaks.com/topic/242512-php-help-not-sure-what-to-call-it/
Share on other sites

It's called GET, can be used in a form or typed directly into the browser with no form, even from a hyperlink you create.

 

http://php.net/manual/en/reserved.variables.get.php

http://www.w3schools.com/php/php_get.asp

http://www.tizag.com/phpT/postget.php

Thank you for a rather quick reply.

I know it's like... $id = $_GET['id'];

But what I didn't understand is how do I get the ?id=200 or whatever to display a web page?

As in, how do I connect the id of 200 with another page?

 

so if I do page.php?id=1 it will redirect to index.php,

but if I do page.php?id=2 it will redirect to about.php

I think you are in the html frame of mind.

 

Here is a simple demo with dummy data representing database results.

http://get.blogdns.com/dynaindex/post-variable.php

 

The code for it is below it, it displays the results of a single post within the same page.

 

php is dynamic, you create the php pages, then the content can be dynamic or set to what you desire.

You should keep your about page static.

 

The dynamic content is usually mysql select queries from a database

 

Lets say you are displaying posts that are split onto a page, like 20 results per page, thats called pagination.

http://www.phpfreaks.com/tutorial/basic-pagination

 

It would have urls like

site.com?page=1

site.com?page=2

site.com?page=3

and so on

 

now for each post on a single page it would have an id number, or at least you should.

so now we can do a "View More" link to display additional information and send them a single page for one id.

lets make a hyperlink for each post id leading them to view.php

<a href="view.php?id=<?php echo $id;?>">View More</a> 

or in a php echo

echo "<a href='view.php?id=$id'>View More</a>"; 

 

view.php contents:

connect to database

$id = $_GET['id'];//could also not be a number but a unique value

sanitize the GET,if this is a number check with is_numeric(), otherwise use mysql_real_escape_string()

mysql select query

echo the results

 

Ah, I see what you mean. What I'd do is create different files for each page and then just include that page in page.php

For example you could structure page.php:

 

<?php
//page header
if(isset($_GET['id']))
{
$id = $_GET['id'];
switch($id)
{
	case 1:
		include 'index.php';
		break;
	case 2:
		include 'about.php';
		break;
	default:
		echo 'Invalid page ID.';
}
}
else
{
echo 'No page selected.';
}
//page footer
?>

 

You could also do it through an array:

 

<?php
//page header
$pages = array(1 => 'index.php',2 => 'about.php');
if(isset($_GET['id']))
{
$id = $_GET['id'];
if(array_key_exists($id,$pages))
	include $pages[$id];
else
	echo 'Invalid page ID.';
else
{
echo 'No page selected.';
}
//page footer
?>

 

Then inside each page you'd just have the content for that page exclusively, without the header and footer obviously.

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.