Handy PHP
Forum
Welcome, Guest
Please Login or Register.    Lost Password?
Creating Your First Template Driven PHP Website Part 2
(1 viewing) 1 Guest
Go to bottom
TOPIC: Creating Your First Template Driven PHP Website Part 2
#232
vujsa
Moderator
Posts: 143
graph
User Offline Click here to see the profile of this user
Re:Creating Your First Template Driven PHP Website 4 Years, 8 Months ago Karma: 5
Well, I don't see any coding errors but your ordering is off.

You are performing a search for the value of $title but you haven't set the value for $title. Move all of the operations related to declaring a value for $title to the top. If it were me, I'd do it more like this:

CODE

<link href="css/template.css" rel="stylesheet" type="text/css" />

<?php require('include/connection.php');
require('include/functions.php');

// Get initial data and assign variables first.
$title = str_replace('-', ' ', $_GET['title']);

// Get secondary data from the database
$query="SELECT * FROM content WHERE title='$title'";
$result1=mysql_query($query);
mysql_close();

// Use all of the data obtained from various sources
$content_id=mysql_result($result1,$i,"content_id"«»);
$desc=mysql_result($result1,$i,"desc"«»);
$sef = stringForUrl($title);

// Finally, generate some output variables.
$site_title = "Made In Shropshire Demo Site";
$page_title = "$title";

$main .= "<a href=index.php?title=$sef>$title</a><hr>$desc";

// Last but not least, load the template that uses all of these
// variables.
require('include/template_includes.php');
?>


With a few exceptions, PHP reads and executes code from the top to the bottom so the order you place the various portions of your code is very important.

Also, I generally prefer to place the PHP code before everything else in a webpage wo allow the parser to get to work quicker. Of course mixed PHP/HTML or so called embedded PHP is placed where it is place!


As for the other "PHP" forums, many of those hard code PHP coders and developers have a hard time relating to new PHP users. Some times they feel that the question is beneath them so they don't bother and the ones that want to help frequently don't posses the knowledge needed to answer the question. Additionally, many people won't try to figure out what the person needs if they don't immediately understand the question. As a result, you really need to ask very detailed questions since coders tend to want to give very quick and easy answers.

I try to answer the question even if I don't fully understand with the hope that a better dialog will develop and I try to explain the answer so that the user will not just learn how to fix their problem but also learn how to adapt that skill to future projects. Kind of the give the man a fish and he eats for a day or teach the man to fish and he will eat for a lifetime kind of deal.

I hope this helps.
vujsa
 
Logged Logged
 
Do not post small or one line posts.
Do not post unsolicited links or any referal links.
Do not post copied content.
Do not use foul language.
Always be respectful to the other posters.
  The administrator has disabled public write access.
#233
amwd07
Fresh Boarder
Posts: 5
graphgraph
User Offline Click here to see the profile of this user
PHP Slideshow Gallery 4 Years, 8 Months ago Karma: 0
 
Logged Logged
  The administrator has disabled public write access.
Go to top
Wordtracker