I'm making a new website with 5 PHP Incs and i was wondering if you click on a link is there away that only the middle include will change to speed up load time? Thanks
Hi Are you talking about say a content site, and then only the center part changes with diffrent links? PS: Did i sell you a tank-o-matic
Ok, frames = bad This is a simple way So to link to home you would go to index.php?page=home To go to contact index.php?page=contact And so on Add this some where before you do the include in index.php PHP: <? $page = striptags($_GET['page']); if (empty($page)) { $page = "home"; } if ($page == "home") { $toinc = "content/home.php"; } elseif ($page == "contact") { $toinc = "content/conact.php"; } elseif ($page == "etc") { $toinc = "content/etc.php"; } else { $toinc = "content/link to a 404 error page.php"; } ?> Pretty basic , might need something more on the striptags bit cant quite remember what you need off the top of my head Then say in your table inbetween the <td>'s or something PHP: <? include $toinc; ?> Should just about do it I hope The are other ways, i always have done it that way, if you have many files then its easier to use some other code
i'm lost now here is my code: PHP: <html> <head> <link rel="stylesheet" type="text/css" href="style.css"/> <title>:: Half Review :: For all your computer needs</title></head> <body topmargin="0"> <div id="container" topmargin="0"> <div id="banner"><?php include('banner.php'); ?></div> <div id="sidebar-a"><?php include('left.php'); ?></div> <div id="sidebar-b"><?php include('right.php'); ?></div> <div id="content"><?php include('content.php'); ?></div> <div id="footer"><?php include('footer.php'); ?> </div> </div> </body> </html>
PHP: <?php $page = striptags($_GET['page']); if (empty($page)) { $page = "home"; } if ($page == "home") { $toinc = "content/home.php"; } elseif ($page == "contact") { $toinc = "content/conact.php"; } elseif ($page == "etc") { $toinc = "content/etc.php"; } else { $toinc = "content/link to a 404 error page.php"; } ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"/> <title>:: Half Review :: For all your computer needs</title></head> <body topmargin="0"> <div id="container" topmargin="0"> <div id="banner"><?php include banner.php; ?></div> <div id="sidebar-a"><?php include left.php; ?></div> <div id="sidebar-b"><?php include right.php; ?></div> <div id="content"><?php include $toinc; ?></div> <div id="footer"><?php include footer.php; ?> </div> </div> </body> </html> edit:: don’t like all the elseif's would be tempted to put in some form of array/database if its a big site.
Ive just done links via an include, its discussed in my thread here not sure if it will help but it sorted me out.
do i need to do any thing to PHP: <?php include('content.php'); ?></div> also do i just use the normal code for linking?
Switches are your friend. If you've got more than one else, you really should look at switching. PHP: switch ($_GET['page']) { case 'home': $toinc = 'home.php'; break; case 'contact': $toinc = 'contact.php'; break; default: $toinc = 'index.php'; break; } # end switch include_once('content/'.$toinc); If you wanted, you could include a case for index and default to error.php, whatever you like.
Some good replies there Mine was only a simple bit of code really for beginners PHP: <?php $page = $_GET['page']; $page = "content/".$page.".php"; if(isset($page)){ if(file_exists($page)){ include($page); } if(!file_exists($page)){ include('errors/404.php'); } } if(!isset($page)){ include('pages/home.php'); } ?> not the most secure code ever but its ok
i would have gone with that, but Hwulex tends to be right so his way is probably quicker. PHP: <?php $pages = array( 'home' => 'index.php', 'news' => 'news.php', 'blog' => 'blog.php', 'contact' => 'contact.php', 'forums' => 'forums.php' ); if(!$_GET['page']) {$page = $pages[home];} else { $page = $pages[$_GET['page']]; if(empty($page)) $page = 'error.php'; } include_once('content/'.$page); ?> //now things are starting to get messy .
Messy but you gain the ability to dynmaicaly generate your page list, which for some cases may be a bonus.
missed that bit index.php?page=home //that would include the home page file. index.php?page=news //that would include the news page file. ...... so <a href="index.php?page=home" >Home</a> <a href="index.php?page=news" >News</a> ...... edit :: bare in mined that php on a Linux server is case sensitive. so Home is not the same as home.
you have just all lost me . Is there a guide that will show me how to do it an easy way? Here is the code for the home page and the code for the left inc with the links PHP: <?php $page = striptags($_GET['page']); if (empty($page)) { $page = "home"; } if ($page == "home") { $toinc = "index.php"; } elseif ($page == "contact") { $toinc = "content/conact.php"; } elseif ($page == "etc") { $toinc = "content/etc.php"; } else { $toinc = "content/link to a 404 error page.php"; } ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"/> <title>:: Half Review :: For all your computer needs</title></head> <body topmargin="0"> <div id="container" topmargin="0"> <div id="banner"><?php include('banner.php'); ?></div> <div id="sidebar-a"><?php include('left.php'); ?></div> <div id="sidebar-b"><?php include('right.php'); ?></div> <div id="content"><?php include("content.php"); ?></div> <div id="footer"><?php include('footer.php'); ?> </div> </div> </body> </html> left: PHP: <link href="style.css" rel="stylesheet" type="text/css"> <div id = "Navs"> Navigations </div> <div id = "table"> - <a href="index.php" class="links">Home</a><br> - <a href="index.php?page=reviews" >Reviews</a><br> - Articles<br> - Guides<br> - Contact Us<br> - Forums<br> </div> <br> <div id ="Navs"> Downloads </div> <div id = "table"> - Latest Downloads<br> - Updates<br> - utilis<br> - Submit<br> </div> <br> <div id = "Navs"> Interactive </div> <div id = "table"> - Readers Drives<br> - PC Gallery<br> - 3D Mark Scores<br> - Mods Shop<br> </div>
Change <div id="content"><?php include("content.php"); ?></div> to <div id="content"><?php include($toinc); ?></div>
Mine was more of a general programming pointer for all rather than a solution to the posted problem (shamefully).