Duepilind Posted February 19, 2009 Share Posted February 19, 2009 Hello, I've been using a rather simple tab menu/website structure. Each tab link referred to an include located within a switch statement. Thus, all page changes took place within the index file. Here is a condensed version of my Index file. <?php $highr = ($_GET['page']); ?> <ul id="nav"> <?php // This is the script for the menu // Menu items $mainMenu['Home'] = 'index.php?page=home'; $mainMenu['Music'] = 'index.php?page=music'; $mainMenu['About'] = 'index.php?page=about'; //This part creates the above menu items as tabs foreach ($mainMenu as $menu => $link) { echo '<li><a href="'.$link.'"'; //Identifies the active page, if active the tab is given the class="active" $wadr = $link; $parts = explode("=",$wadr); $wadr = $parts['1']; if ($highr == $wadr){ echo ' class="active"'; } echo '>'.$menu.'</a></li>'; } ?> </ul> <table><tr><td> <?php //This is where the pages appear switch ($_GET['page']) { case "home": include('home.php'); break; case "music": include('music.php'); break; case "about": include('about.php'); break; default: include('start.php'); break; } ?> </td><td> <?php // This content will not change include('sidebar.php'); ?> </td></tr></table> What I like about this, and want to keep, is the possibility to link directly to a tab through the address bar, for example, writing http://www.domain.com/index.php?page=home would get me to the home tab of my website. However, the current limit is that every time I click a tab, the entire website reloads. Instead, and what I need assistance with, is a method so only the switch method changes rather than the entire website reloads. Any suggestions? I'm assuming the end-result will approach something like the tab system on the following page: http://www.theoldecookerybook.com/~theopden/wiki/index.php/Colonel_Plomer%27s_Shrewsbury_Cake#tab=Original_text But I'm unsure how to go about this. Thank you beforehand for any assistance! Link to comment https://forums.phpfreaks.com/topic/145843-solved-loading-a-page-within-a-page-without-reloading-the-entire-page/ Share on other sites More sharing options...
jackpf Posted February 19, 2009 Share Posted February 19, 2009 PHP is parsed before it is sent to the page, so unless you use AJAX, you can't parse it without refreshing the page. It'd probably be quite easy with AJAX tbh, something like each nav link sends a variable to the server via httpRequest, eg. page=music, and your index file can return the respective page. Hope this helps... Link to comment https://forums.phpfreaks.com/topic/145843-solved-loading-a-page-within-a-page-without-reloading-the-entire-page/#findComment-765722 Share on other sites More sharing options...
haku Posted February 19, 2009 Share Posted February 19, 2009 The last poster touched on it, but basically you want to use AJAX. It's a method combining javascript and a server side language (usually). Basically, javascript makes calls to the server in the background to get the data you need. Link to comment https://forums.phpfreaks.com/topic/145843-solved-loading-a-page-within-a-page-without-reloading-the-entire-page/#findComment-765733 Share on other sites More sharing options...
Duepilind Posted February 19, 2009 Author Share Posted February 19, 2009 Thank you very much, I'll see what I can do! Link to comment https://forums.phpfreaks.com/topic/145843-solved-loading-a-page-within-a-page-without-reloading-the-entire-page/#findComment-766034 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.