Perry| Posted August 11, 2008 Share Posted August 11, 2008 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 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
Perry| Posted August 11, 2008 Author Share Posted August 11, 2008 Smarty? What is that Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 A templating system. Google it and you'll get the site. It has enough documentation to get you started. Quote Link to comment Share on other sites More sharing options...
Perry| Posted August 11, 2008 Author Share Posted August 11, 2008 Thank you, I'll leave this topic unsolved to get some more replies on different ways to do it. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
Perry| Posted August 11, 2008 Author Share Posted August 11, 2008 <?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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
Perry| Posted August 11, 2008 Author Share Posted August 11, 2008 Thank you for your posts, I'll look into Smarty however I am looking for other alternatives to it. Quote Link to comment Share on other sites More sharing options...
gabrielkolbe Posted August 11, 2008 Share Posted August 11, 2008 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'); ?> Quote Link to comment Share on other sites More sharing options...
Perry| Posted August 11, 2008 Author Share Posted August 11, 2008 Sorry what do you mean? Quote Link to comment Share on other sites More sharing options...
Perry| Posted August 11, 2008 Author Share Posted August 11, 2008 Could you give an example of what you mean? Quote Link to comment Share on other sites More sharing options...
Perry| Posted August 11, 2008 Author Share Posted August 11, 2008 Bump Quote Link to comment Share on other sites More sharing options...
Perry| Posted August 12, 2008 Author Share Posted August 12, 2008 Still need a method. Quote Link to comment Share on other sites More sharing options...
Perry| Posted August 12, 2008 Author Share Posted August 12, 2008 Bump Quote Link to comment Share on other sites More sharing options...
spasme Posted August 12, 2008 Share Posted August 12, 2008 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 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.