Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jasonbot

macrumors 68020
Original poster
Aug 15, 2006
2,467
0
The Rainbow Nation RSA
Hi everyone. I have an html site that I've converted to php with the help of a friend. Unfortunately he's very busy and I'm just hoping someone else can help me get it going.

The html site is here:
jasonbot.googlepages.com/index.html

The php site is here:
http://grupenet.com/jasonbot/main.php

The problem I am currently experiencing is that the text in the php site (that I got via a switch statement) is not adhering to my stylesheets. I don't know how to fix it and I'm sure its a very basic thing that I need to do as I have a feeling that my <p> tags just wont cut it.


the switch:
PHP:
<p align="center" id="middle">
<?php
$pg = $_GET['pg'];

switch ($pg) {
default:
include "home.html";
break;
}

?>
</p>

the css:
HTML:
p#middle{
background:url(body.png) center repeat-y;
margin-left:100px;
margin-right:100px;
padding-right:100px;
padding-left:100px;
margin:0;
}


thanks in advance
 
why have the switch in there? why not just have your $pg variable match up with the name of the file and include it?

PHP:
<?php

// $pg = home in this case

$pg = $_GET['pg'];

include('/direct/path/to/$pg.php');

?>
 
PHP5 is strict these days so...

PHP:
$pg=(isset($_GET('pg') && !empty($_GET('pg')) && intval($_GET('pg'))>0) ? intval($pg) : "1";

That makes sure the $pg variable is set properly only if the URL has that argument, it's not blank and a valid integer. I default it to one since this seems to be a variable for a page number, and page 1 is a sensible default for their home page. I could add even more security to account for SQL injection and XSS issues such as trimming, stripping HTML tags, etc. - developers be aware of these things when working with $_GET globals.

I suspect the OP will expand the branches of the switch to include more than just the default in the future. If not, then I agree the switch is not necessary.

-jim
 
Guys come on.... I figured it. It was the fact that I was using <p> instead of <div> lol. Well thats sorted but now I got a problem with my linkies.

If you look @ this page: grupenet.com/jasonbot/main.php?pg=connect
I'm having some problems with my switch statement.

•When I click one of the sublinks the page changes to the wrong content and teh links disappear
•The image rollovers are funny :/

Help please and thank you
 
•The image rollovers are funny :/

The problem here is that you are using the same id name for the buttons in the top navigation. Rename your second nav buttons id names to something unique and update your onmouseover and onmouseout respectively.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.