homepage Welcome to WebmasterWorld Guest from 54.196.197.153
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?...
Echo_Tyme




msg:1313750
 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?

thanks

 

Galaphile




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

You would do something like this.
<?php
$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>

Echo_Tyme




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

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

Echo_Tyme




msg:1313753
 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?

coopster




msg:1313754
 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...

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

Echo_Tyme




msg:1313755
 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---

<?php
include("/include/header.php");

echo $main;

include("/include/4_side.php");
?>

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

---Header.php---

<?
$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.

stevenmusumeche




msg:1313756
 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.";

Echo_Tyme




msg:1313757
 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?

coopster




msg:1313758
 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?
Echo_Tyme




msg:1313759
 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