Hi,
Ok starting my site again using CSS and I want to cut down on as much duplicate code as possible. Ok so here is the code to load one page of my site. I do this by putting a ?Section=Whatever in the url, it then picks out what Section is required and loads the relevant page.
<?
$Section = $_REQUEST['Section'];
$intSession =$_SESSION['level'];
$PremiumMembers = "scripts/members-premium.inc";
$FreeMembers = "scripts/members-only.inc";
// Determine What Main Page to include
If (isset($Section))
{
switch ($Section) {
Case "UK":
$PageLoad = "scripts/meetings-list.inc";
$AccessLevel = 0;
break;
Case "International":
$PageLoad = "scripts/format2.inc";
$AccessLevel = 2;
$TableSelect = "international_meetings";
$TableID = "14";
break;
Case "Calls":
$PageLoad = "scripts/format2.inc";
$AccessLevel = 2;
$TableSelect = "calls";
$TableID = "15";
break;
}
} Else
{
//Load index if section was not supplied
$PageLoad = "scripts/meetings-index.inc";
$AccessLevel = 0;
}
If ($intSession >= $AccessLevel)
{
$PageLoad =$PageLoad;
}
Elseif ($AccessLevel == 3)
{
$PageLoad =$PremiumMembers;
}
ElseIf ($AccessLevel == 2)
{
$PageLoad =$FreeMembers;
}
include ($PageLoad);
?>
What I want to know is a lot of my pages have a similar format, they have text that comes from the database and a list of other information in a specific table. So, above the sections International and Calls have the same format. They have text and select from the same table.
So in the file format2.inc I want something like this:
<?
$query = "SELECT * FROM $TableSelect WHERE id = $TableID";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// Ouput Code
?>
Is what I am doing correct and will it work?
Many thanks,
Chris