Jump to content

Constructing dynamic pages


hdpb

Recommended Posts

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:

layout.gif

Link to comment
Share on other sites

I would have posted this in the PHP forum, but I am not one of this critical people.  ;D

 

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.