Page 1 of 1

What am i doing wrong? *help*

Posted: Mon Jul 21, 2003 5:16 pm
by illicit
Hey, could you please please please, help me? i have been struggling on this script for some time now and i cant seem to understand where the **** i am going wrong :? ooh well, it mainly consists of two parts.. the "Required part" and the page it self
(page.inc)

<body leftmargin = 0 topmargin = 0 marginwidth = 0 marginheight = 0>
<?
class Page
{

var $content;
var $title = "MySite";
var $buttons = array( "Home" => "home.php",
"Contact" => "contact.php",
"Services" => "services.php",
"Site Map" => "sitemap.php"
);

//class pages operations
function SetContent($newcontent)
{
$this->content = $newcontent;
}

function SetTitle($newtitle)
{
$this->title = $newtitle;
}

function SetButtons($newbuttons)
{
$this->buttons = $newbuttons;
}

function Display()
{
echo "<html>\n<head>\n";
$this -> DisplayTitle();
$this -> DisplayStyles();
echo "</head>\n<body>\n";
$this -> DisplayHeader();
$this -> DisplayMenu($this->buttons);
echo $this->content;
$this -> DisplayFooter();
echo "</body>\n</html>\n";
}

function DisplayTitle()
{
echo "<title> $this->title </title>";
}

function DisplayStyles()
{
?>
<style>
h1 {color:white; font-size:24pt; text-align:center; font-family:arial,sans-serif}
.menu {color:white; font-size:12pt; text-align:center; font-family:arial,sans-serif; font-weight:bold}
td {background:black}
p {color:black; font-size:12pt; text-align:justify; font-family:arial,sans-serif}
p.foot {color color:white; font-size:9pt; text-align:center; font-family:arial,sans-serif; font-weight:bold}
a:link,a:visited,a:active {color:white}
</style>
<?
}
function DisplayHeader()
{
?>
<table width = 100% cellpadding = 12 cellspacing = 0 border = 0>
<tr bgcolor = white>
<div align=center><img alt="My Site" src="pics\logo.gif" /></div>
</td>
</tr>
</table>
<?
}
function DisplayMenu($buttons)
{
echo "<table width = \"100%\" bgcolor = white"." cellspading = 4 cellspacing = 4>\n";
echo "<tr>\n";

$width = 100/count($buttons);

while (list($name, $url) = each($buttons));
{
$this -> DisplayButton($width, $name, $url, !$this->IsURLCurrentPage($url));
}
echo "</tr>\n";
echo "</table>\n";
}
function IsURLCurrentPage($url)
{
if(strpos( $GLOBALS["SCRIPT_NAME"], $url )==false)
{
return false;
}
else
{
return true;
}
}
function DisplayButton($width, $name, $url, $active = true)
{
if ($active)
{
echo "<td width = \"$width%\">
<a href = \"$url\">
<img scr = \"s-logo.gif\" alt = name \"$name\" border = 0></a>
<a href = \"$url\"><span class=menu>$name</span></a></td>";
}
else
{
echo "<td width = \"$width%\">
<span class=menu>$name</span></td>";
}
}

function DisplayFooter()
{
?>
<table width = 100% bgcolor = black cellspadding = 12 border = 0>
<tr>
<td>
<p class=foot>&copy My Site 2k - 2k3</p>
</td>
</tr>
</table>
<?
}
}
?>

End of Page.inc[\b]


This is the acctual page

(Index.php)

<?PHP

require ("page.inc");

$homepage = new Page();

$homepage -> SetContent("<p>I need help :\</p>");

$homepage -> Display();

?>


Posted: Mon Jul 21, 2003 5:31 pm
by m@ndio
whats wrong with it...?

Posted: Mon Jul 21, 2003 6:24 pm
by Gen-ik
I've just quickly scanned through your code and noticed this.....

Code: Select all

function DisplayTitle() 
&#123; 
echo "<title> $this->title </title>"; 
&#125; 

function DisplayStyles() 
&#123; 
?> 
<style> 
h1 &#123;color:white; font-size:24pt; text-align:center; font-family:arial,sans-serif&#125; 
.menu &#123;color:white; font-size:12pt; text-align:center; font-family:arial,sans-serif; font-weight:bold&#125;
..check out what appears just above the style tag.

I don't think closing PHP halfway through a function() is a sensible thing to do :roll:

...

Posted: Mon Jul 21, 2003 8:07 pm
by kettle_drum
It all works fine for me.

Have you got the page.inc in the same directory as the index page?

Posted: Wed Jul 23, 2003 3:20 pm
by illicit
well you see, there is a small problem.. it is supposed to erect a button(s) and if you look closly i used a array to store all the button names and url's.. doesnt make sense :\

Posted: Wed Jul 23, 2003 5:16 pm
by qartis
Closing php at any point (well, within reason) is fine, as long as you open it up again to close the curly brace.