|
Posted by max on 08/29/05 18:19
On 29 Aug 2005 06:01:01 -0700, "J Smith" <halfanorange@gmail.com> wrote:
>I'm making a website where each page has the same design, obviously its
>a bad idea to put the same code/html in each page so what is the best
>way to do this?
>
>What I'm doing at the moment is putting a file called 'index.php' and a
>file called 'content.php' in each directory. 'index.php' would set a
>variable called $content with the full path for 'content.php' then it
>would have an include() statement which called a script outside
>public_html called 'template.php'. 'template.php' would be the basic
>template for every page and where the content is it would have the line
>'include($content);'. Here's what my scripts basically look like:
>
>--
>/www/mysite/public_html/subpage/index.php:
>
><?php
> $content = "/www/mysite/public_html/subpage/content.php":
> include("/www/mysite/private_html/template.php");
>?>
>--
>/www/mysite/public_html/subpage/content.php:
>
><h2>Content goes here</h2>
>--
>/www/mysite/private_html/template.php
>
><title>mysite</title>
><h1>welcome to my site</h1>
><?php include($content); ?>
If you have access to an MySQL database (and most web hosts offer this for
notta lotta money these days) you can have an index file carrying a list of
content records in a database.
The principle behind it is that you identify to your content.php file which
record in the database you want to display.
Unless the directory structure is essential to your design, you should be
able to do without it.
In index.php, you might have -
$TableName="titles_of_content";
$Query="SELECT title_of_content FROM $TableName";
$Result=mysql_db_query ($DBName, $Query, $Link);
while ($Row=mysql_fetch_array($Result))
{
print("<a href=\"content.php?id=$Row[title_of_content]\"></a>");
}
This prints out a clickable URL for each "title_of_content" record in the
database; run your cursor over the list and you'll see the id= change.
In content.php, you have -
$TableName="titles_of_content";
$Query="SELECT * FROM $TableName WHERE title_of_content='$title_of_content'
";
$Result=mysql_db_query ($DBName, $Query, $Link);
while ($Row=mysql_fetch_array($Result))
{
do things
}
Put
php "passing variables" tutorial
into google and try any one of the numerous results you feel comfortable
reading.
HTH.
Navigation:
[Reply to this message]
|