homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Dynamic page HTML code question
Is this ok?...

 11:25 pm on Jul 20, 2004 (gmt 0)

I'm gonna have all my pages load up a dynamic header and footer, depending on what variable I call up.

So at the beginning of my code it will call for a banner, this banner will be set as a variable in a seperate page that i'll call up.

Now i'm wondering, can the page I call up (with a list of variables) have HTML code in it, like this:

$main = "<center><div style="text-align:center;width:740px; background-color:#000066;"><img src="/images/v4_main.jpg"></div></center>";

if not, then how can I call up a variable in that code? Where would i put it and have to call it up, is there a way?




 3:31 am on Jul 21, 2004 (gmt 0)

You would do something like this.
$main = "<center><div style="text-align:center;width:740px; background-color:#000066;"><img src="/images/" .$imagename ."></div></center>";

And then echo it, or display it however you want.

That would produce something like <center><div style="text-align:center;width:740px; background-color:#000066;"><img src="/images/myfilename.jpg></div></center>


 3:58 am on Jul 21, 2004 (gmt 0)

So i'm allowed to put HTML code in the php variables?


 5:40 am on Jul 21, 2004 (gmt 0)

Not letting me edit...

Anyway I have another question. All the pages on my site will need this variable page to be called, how do I call the page... but just with the variable I want.

So if 100 pages all have a code for this variable, what code would be used... to open the page and the variable. Along with this I don't want all these variables to open, jsut one.

I was thinking of a:

include (/include/header.php)
echo $main

Would that be the correct way of opening it?


 12:25 pm on Jul 21, 2004 (gmt 0)

So i'm allowed to put HTML code in the php variables?

Absolutely. It's quite common. Take, for example, times when you want to load up a table. You can build the rows and columns in a loop, all the time inserting your markup...

$table_data = ''; // initialize
while (looping through my data set) {
$table_data .= '<tr><td>';
$table_data .= $my_data_set['variable'];
$table_data .= '</td></tr>';
print $table_data;


 9:08 pm on Jul 21, 2004 (gmt 0)

That confused me lol, I'm not too good at php yet, just crawling into it.

Now I tried to include the header.php page that has all teh variables, but it's coming up with an error.

---My Page---


echo $main;


---End--- (Just the php portion)


$main = "<center><div style="text-align:center;width:740px;"><img src="/images/v4_main.jpg"></div></center>";

$about = "<center><div style="text-align:center;width:740px;"><img src="/images/v4_about.jpg"></div></center>";

$fix = "<center><div style="text-align:center;width:740px;"><img src="/images/v4_fix.jpg"></div></center>";

$guard = "<center><div style="text-align:center;width:740px;"><img src="/images/v4_guardian.jpg"></div></center>";

$net = "<center><div style="text-align:center;width:740px;"><img src="/images/v4_net.jpg"></div></center>";

$maint = "<center><div style="text-align:center;width:740px;"><img src="/images/v4_maintenance.jpg"></div></center>";

$remove = "<center><div style="text-align:center;width:740px;"><img src="/images/v4_remove.jpg"></div></center>";

$spy = "<center><div style="text-align:center;width:740px;"><img src="/images/v4_spyware.jpg"></div></center>";

$virus = "<center><div style="text-align:center;width:740px;"><img src="/images/v4_virus.jpg"></div></center>";

Wait I prlly need to have the full directory for the images... like the "http://" portion right or wrong? lol. It always makes me put in the full URL or it won't work... not sure if it applies now.

Anyway the error is...

Parse error: parse error, unexpected T_STRING in C:\Inetpub\accounts\mm.intellstat\include\header.php on line 2

Notice: Undefined variable: main in C:\Inetpub\accounts\mm.intellstat\guardian.php on line 22

And that always seems to happen to me and I dunno how in the world to fix it, I tried but it comes back over and over.


 9:15 pm on Jul 21, 2004 (gmt 0)

You have to escape special characters, including the double quote symbol. So if you want to show ", you need to have it be \" in your string.

$thestring="Steven loves \"Webmasterworld\" very much.";


 4:55 am on Jul 22, 2004 (gmt 0)

Ok the variable in header.php is good, taht error is gone... now I still ahve the other one...

Notice: Undefined variable: main in C:\Inetpub\accounts\mm.intellstat\guardian.php on line 22

That line is just...

echo $main;

it's not reading $main from header.php... I have the page included but it's nto reading from it, how do I make it read from that page?


 2:22 pm on Jul 22, 2004 (gmt 0)

That is a notice error telling you that you are trying to use a variable at a point in your script where it has not yet been defined. I see
header.php and 4_side.php referenced here, but where is guardian.php included?

 3:43 pm on Jul 22, 2004 (gmt 0)

guardian.php is the page ur viewing, guardian.php is a page that has all the main information, such as the header, html coding (of the main tables), etc.

The header (banner and menu) is a dynamic page, along with 4_side, 4r_side and bottom.php. The middle table is the only acutal thing that is guardian.php.

That's why this is so odd because i'm taking a page that your calling and trying to add another page to it. So i'm calling guardian.php and then I want that to call header.php and load up whatever variable I have in place. There has to be a way somewhere lol.

Basically if you view my entire site, you'll see the top, sides and bottom all the same (for the most part) and the main content is all that really changes, the main content is the actual PAGE ur calling, the rest are just dynamic.

So what i'm really asking is, is there a way to call up header.php and have it load up a variable I chose, even though it will be a dynamic page.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved