Jump to content

Need help creating a dynamic website.


Perry|

Recommended Posts

Hello.

 

I need some help with creating a dynamic site with PHP. I'll cut strait to it and say what I need to do.

 

I have made a template with PHP includes;

 

<?php include('inc/headinc.php'); ?>

<title>Home</title>

<?php include('inc/leftinc.php'); ?>

<?php include('inc/rightinc.php'); ?>

<div class="maincontent">

 

</div>

<?php include('inc/endinc.php'); ?>

 

headinc.php is all the meta data, attached CSS files, and an attached JS file.

leftinc.php is the left part of a table for the main layout.

rightinc.php is the right part of a table containing a CSS drop down menu and a banner.

endinc.php contains Google analytics code, a footer and closes the body and html tags.

 

The parts that need to be dynamic are the title and the div with the class of maincontent.

The mainconent div will hold the data for the page, there will be different type of guides on the site and I want to narrow them down with page Id's for example http://myurl.com/guidetype.php?id=1 etc etc. Also the page title needs to change but if I am using includes to display the data on the page how will I be able to change the title?

 

I think this sounds a bit confusing so please if you do not understand what I mean just ask.

 

Kind Regards,

 

Perry

Link to comment
Share on other sites

I'd check out Smarty for use as a templating system because it's quite good at handling stuff like this.  It's hard to get the title into there without doing all the work before including it, and it's also hard to send headers and stuff in a place that makes sense if you start outputting stuff beforehand, which is where Smarty comes in.  It would allow you to separate business logic from your layout.

Link to comment
Share on other sites

I mean, you don't need to use a templating system, but it just often ends up being cleaner.  I'm sure you could do some query in headinc.php to get the title based on some $_GET parameter and then set it to $title and it'll be available to put into the <title> tags then, but it'll get kinda sloppy and confusing.  =P  Also, is the <title> tag in the <head> tag of the document?  Doesn't seem like it based on the position of it.  If it's not, you may want to figure out how to get it there so that it validates.

Link to comment
Share on other sites

<?php include('inc/headinc.php'); ?>

<title>Home</title>

<?php include('inc/leftinc.php'); ?>

 

leftinc.php ends the head tag, sorry for not pointing that out.

 

I was thinking if I store all the data in a database? I'm not sure really.

Link to comment
Share on other sites

Oh, just wanted to make sure on that. xD  Anyway, that's what I meant by $_GET parameter.  You'd use the ID from GET in the query to get the title and stuff from the database.  But still, I find it rather sloppy compared to a templating engine.  You have the business logic of the application tied too closely into the layout logic.

Link to comment
Share on other sites

Simple change your layout to;

 

<?php include('inc/headinc.php'); ?>

<?php include('inc/sql.php'); ?>

(run all your queries here then the rest of the page, title ect will be dynamic)

<title>Home</title>

<?php include('inc/leftinc.php'); ?>

<?php include('inc/rightinc.php'); ?>

<div class="maincontent">

 

</div>

<?php include('inc/endinc.php'); ?>

 

Link to comment
Share on other sites

I'm not sure i understand exactly what you want done... this is what i understood:

 

// DB Conn.
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName");

<?php include('inc/headinc.php'); ?>
// Select Something
$result = mysql_query("SELECT * FROM $table") or die ("Could not read data because ".mysql_error());
$qry = mysql_fetch_array($result)

<title><? echo $qry[title]; ?></title>
<?php include('inc/leftinc.php'); ?>
<?php include('inc/rightinc.php'); ?>
<div class="maincontent">

</div>
<?php include('inc/endinc.php'); ?>

 

Let me know if this is relevant to what you need done.

Cheers

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.