hdpb Posted April 6, 2008 Share Posted April 6, 2008 I'm building a website where I will have a table of around 20 or so links at the top. After clicking a link, I want the resulting page to be the same as my index (layout wise) but with PHP bringing the appropriate data from a database into the body. I already know how to do that, but how can I make this process easier than building 20 separate pages? I probably didn't do a very good job of explaining the first part, so here's a diagram of the layout: Quote Link to comment Share on other sites More sharing options...
haku Posted April 7, 2008 Share Posted April 7, 2008 Use a $_GET variable to figure out what information should be showing, then have your page show the appropriate information. This will mean you only have to make one page. Quote Link to comment Share on other sites More sharing options...
947740 Posted April 11, 2008 Share Posted April 11, 2008 I would have posted this in the PHP forum, but I am not one of this critical people. I would use the $_GET variable that haku mentioned, but I have some more advice. I am not quite sure how to use the $_GET, because I mainly use $_POST, but you are working with links. Here is the basic layout: <html> <head> <title>Example</title> </head> <body> <h1>Header</h1> <p>Various links go here.</p> <?php if(isset($_GET['linkname'])) { // Connect to database, get results you want. //Then just echo the link dependent information here. } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
wrathican Posted April 11, 2008 Share Posted April 11, 2008 look up the switch statement Quote Link to comment Share on other sites More sharing options...
atravotum Posted April 19, 2008 Share Posted April 19, 2008 I agree with the method above, you will have to create a statement that runs a check for the link clicked, then pulls the data from a database and displays it. However I was going to mention... If you wanted to take it a step further and have the content update upon clicking the link w/out having to reload the page you should look into incorporating ajax into your script. You could use the ajax to send an xmlhttp request to pull the data and update a div layer holding your body content without needing extra pages, or reloading the page as the usual php request methods do. Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted April 20, 2008 Share Posted April 20, 2008 Use a $_GET variable to figure out what information should be showing, then have your page show the appropriate information. This will mean you only have to make one page. You use get by having it in the url ... mysite.com/index.php?page_id=1 <?php $page_id = $_GET['page_id']; // Then query db for appropriate data. ?> Anyway, make sure you create a site map so google will be able to crawl your "Dynamic" webpage. Quote Link to comment 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.