Click to See Complete Forum and Search --> : [RESOLVED] Hi I problem getting a simple dynamic page to work


iiz
12-10-2007, 11:54 PM
i have an index page which basically just has includes and the main html template then i have a page handler script which i have bellow with all the elseif's. all the pages in includes/pages just have $title and $content variables ill include one bellow. i tried replacing the includes in page with
echo "main";
echo "web";
and so forth the output was some like "webmaincontabobrosoft" which is my problem but i dont know how to fix it
index.php:
require ('includes/page.php');
$metakeyword = "web design";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title><?php echo $title; ?></title>
<meta name="keywords" content="<?php echo $metakeyword ?>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/text.css" />
<script src="js/global.js" type="text/javascript"></script>
</head>
<body>
<center>
<table id="main" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table id="container" cellpadding="0" cellspacing="0">
<tr>
<td class="trw1">
<img class="right" src="images/live_sup.png" alt="We offer live 24/7 support" />
</td>
</tr>
<tr class="trg">
<td>
<ul id="menu_bar">
<li><a href="index.php?page=main" class="one"><img src="images/nav_but.gif" alt="" /></a></li>
<li><a href="index.php?page=main" class="two">&nbsp;Home</a></li>
<li><a href="index.php?page=web" class="one"><img src="images/nav_but.gif" alt="" /></a></li>
<li><a href="index.php?page=web" class="two">&nbsp;Web Design</a></li>
<li><a href="index.php?page=bro" class="one"><img src="images/nav_but.gif" alt="" /></a></li>
<li><a href="index.php?page=bro" class="two">&nbsp;Brochures</a></li>
<li><a href="index.php?page=soft" class="one"><img src="images/nav_but.gif" alt="" /></a></li>
<li><a href="index.php?page=soft" class="two">&nbsp;Software Development</a></li>
<li><a href="index.php?page=cont" class="one"><img src="images/nav_but.gif" alt="" /></a></li>
<li><a href="index.php?page=cont" class="two">&nbsp;Contact Us</a></li>
<li><a href="index.php?page=abo" class="one"><img src="images/nav_but.gif" alt="" /></a></li>
<li><a href="index.php?page=abo" class="two" style="width: 55px; height: 25px">&nbsp;About Us</a></li>
<li class="right" style="padding:1px 0px 0px 35px;"><span class="orangetext">Phone:</span>800.MTS.DESI<br />
<span class="orangetext">E-mail:</span>Sales@MTSDD.com</li>
</ul>
</td>
</tr>
<tr>
<td class="trw2">
<?php echo $content; ?>
</td>
</tr>
</table><br />
<span id="foot"><a href="index.php?page=home">Home</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="index.php?page=web">Web Design</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="index.php?page=bro">Brochures</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="index.php?page=soft">Software Development</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="index.php?page=cont">Contact Us</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="index.php?page=abo">About Us</a></span>
</td>
</tr>
</table>
</center>
</body>
</html>

page.php:
<?php
$page = strtolower($page);

if (!isset = $page) {
include ('pages/home.php');
}
else if ($page = 'web') {
include ('pages/web.php');
}
else if ($page = 'bro') {
include ('pages/bro.php');
}
else if ($page = 'soft') {
include ('pages/soft.php');
}
else if ($page = 'cont') {
include ('pages/cont.php');
}
else if ($page = 'abo') {
include ('pages/abo.php');
} else {include ('pages/main.php');}
?>

main.php (im 100% sure issue is not here):
<?php
$title = "MTSDD Professional Web Design, Software Development, and Graphic Design";
$content = "<table style=\"height:282px;\">
<tr>
<td valign=\"top\" style=\"padding:0px; margin:0px;\">
<img src=\"images/main_index.gif\" alt=\"Services Image\" style=\"float:left\" />
</td>
<td valign=\"top\" style=\"padding:0px; margin:0px;\"><img id=\"vline\" src=\"images/vline.gif\" alt=\"\" /></td>
<td style=\"text-align:left;\">
<h2><span class=\"graytext\">Welcome to </span><span class=\"orangetext\">MTS Design &amp; Development</span></h2>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br /><br />
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.<br /><br />
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.<br /><br />
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br /><br />
</td>
</tr>
<tr>
<td colspan=\"3\">
<hr/>
</td>
</tr>
</table>
<table width=\"100%;\">
<tr>
<td>
<span class=\"graytext\" style=\"float:left;font-size:12pt;font-weight:bold;\">&nbsp;Previous Works:</span>
</td>
</tr>
<tr>
<td style=\"width:291px;\">
<div style=\"height:277px;width:291px;border:1px black solid;\">
<a id=\"href\" href=\"http://www.odessapeople.com\" target=\"_blank\">
<img id=\"view\" src=\"images/screen/odessapeople.png\" alt=\"Preview Window\" />
</a>
</div>
</td>
<td valign=\"top\">
<center style=\"background-color:#ffffff;\">
<div id=\"pt\">
<a id=\"thumb\" href=\"javascript:src('view','images/screen/480autotrim.png');href('href','http://www.msobrane.com')\">
<img src=\"images/screen/480autotrim_s.png\" alt=\"480autotrim Thumbnail\" />
</a><br />
<span class=\"orangetext\">URL:</span><a href=\"http://www.msobrane.com\">www.msobrane.com</a><br />
<span class=\"orangetext\">Job:</span> E-Commerce, Logo Design
</div>
<div id=\"pt\">
<a id=\"thumb\" href=\"javascript:src('view','images/screen/odessapeople.png');href('href','http://www.odessapeople.com')\">
<img src=\"images/screen/odessapeople_s.png\" alt=\"Odessapeople Thumbnail\" />
</a><br />
<span class=\"orangetext\">URL:</span><a href=\"http://www.odessapeople.com\">www.odessapeople.com</a><br />
<span class=\"orangetext\">Job:</span> Full Community Site
</div>
<p>Click To View In Window</p>
</center>
</td>
</tr>
</table>";
?>

thank you in advance
-iiz

NogDog
12-11-2007, 01:05 AM
The PHP operator for an equivalence comparison is "==", not "=". Also, isset() is a function that returns a boolean true/false, so you don't really need to compare it to anything.

<?php
$page = strtolower($page);

if (!isset($page)) {
include ('pages/home.php');
}
else if ($page == 'web') {
include ('pages/web.php');
}
else if ($page == 'bro') {
include ('pages/bro.php');
}
else if ($page == 'soft') {
include ('pages/soft.php');
}
else if ($page == 'cont') {
include ('pages/cont.php');
}
else if ($page == 'abo') {
include ('pages/abo.php');
}
else {
include ('pages/main.php');
}
?>

iiz
12-11-2007, 06:35 AM
Thank you for the advice i tried it out am im still stuck with the same problem. When i click a link on the page http://mtsdd.com it somehow points to the home page only.

mahfooz
12-11-2007, 07:15 AM
from where $page gets value from

have u use

$page = $_GET['page'];

AnotherTechGuy
12-11-2007, 08:16 AM
As Mahfooz said - where do you get $page from?

You would need to do a
$page = $_GET['page']; (thinking about security depending on how this is used)
To get the page from the $_GET array. Perhaps you have moved from a reg_globals = 1 to reg_globals = 0 enviroment recently?

Also, I would swap the ifs for a switch statement instead as this is cleaner and quicker.

HTH

NogDog
12-11-2007, 01:46 PM
As Mahfooz said - where do you get $page from?

You would need to do a
$page = $_GET['page']; (thinking about security depending on how this is used)
To get the page from the $_GET array. Perhaps you have moved from a reg_globals = 1 to reg_globals = 0 enviroment recently?

Also, I would swap the ifs for a switch statement instead as this is cleaner and quicker.

HTH
Some crude benchmarking I have done in the past suggests that switch is not necessarily faster than if/elseif/else, and sometimes can be slower. But the differences are generally so small that it's probably best to base the decision on which will be easier to maintain (which would probably be the switch option in most cases).

iiz
12-13-2007, 11:08 PM
I added $_GET['page']; now it seems as though im stuck with one variable which was the first one i clicked on "web" i have added a echo started to display the value of $page. i need a way to clear $page each time the script runs.

New index.php:
<?php

$page = $_GET['page'];
include ('includes/page.php');
$metakeyword = "web design";

$page = "";
?>

New page.php:
<?php

$page = strtolower($page);

if ($page = '') {
include ('pages/home.php');
}
elseif ($page = 'web') {
include ('pages/web.php');
}
elseif ($page = 'bro') {
include ('pages/bro.php');
}
elseif ($page = 'soft') {
include ('pages/soft.php');
}
elseif ($page = 'cont') {
include ('pages/cont.php');
}
elseif ($page = 'abo') {
include ('pages/abo.php');
}
else {
include ('pages/home.php');
}
echo $page;
?>

AnotherTechGuy
12-14-2007, 03:43 AM
You still have

if ($page = 'cont')

instead of

if ($page == 'cont')

Same for all the rest of them too...

Just for your info
$var = "string" make the variable $var contain "string"
$var == "string" tests to see if $var is equal to string

HTH

Pete