Forbsie1888 Posted July 21, 2011 Share Posted July 21, 2011 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 >.< Quote Link to comment https://forums.phpfreaks.com/topic/242512-php-help-not-sure-what-to-call-it/ Share on other sites More sharing options...
QuickOldCar Posted July 21, 2011 Share Posted July 21, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/242512-php-help-not-sure-what-to-call-it/#findComment-1245504 Share on other sites More sharing options...
Forbsie1888 Posted July 21, 2011 Author Share Posted July 21, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/242512-php-help-not-sure-what-to-call-it/#findComment-1245505 Share on other sites More sharing options...
QuickOldCar Posted July 21, 2011 Share Posted July 21, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/242512-php-help-not-sure-what-to-call-it/#findComment-1245516 Share on other sites More sharing options...
Porl123 Posted July 21, 2011 Share Posted July 21, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242512-php-help-not-sure-what-to-call-it/#findComment-1245519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.