Link to home
Start Free TrialLog in
Avatar of davidsperling
davidsperling

asked on

How to add dynamic PHP content to static CSS layout example?

There are some nice layout examples in Chapter 8 in this bok - Web Designers Reference
http://www.friendsofed.com/download.html?isbn=1590594304

So, if some of the data comes from a database via php, what would the code look like?

Please provide some simple, conceptual snippets!

(In a non MVC style, I'll do that later ;-)


Avatar of MMDeveloper
MMDeveloper
Flag of United States of America image

would all depend on where the data is processed, what the structure of the data looks like etc...

Here is how you would populate a select list assuming the database info has arleady been retrieved and processed into a single-dimension array
<select name="state" id="state">
	<?php
		foreach ($states as $k => $v) {
			echo '<option value="' . $v . '">' . $v . '</option>';
		}
	?>
</select>

Open in new window

Avatar of davidsperling
davidsperling

ASKER

I know PHP/Mysql already :-) I have a working frame based site that looks like s-t. Now I want to remake it with a nice, proffesional CSS based layout!
(ie Chapter 8\08_p223_css_switchers in http://www.friendsofed.com/download.html?isbn=1590594304 )
I mean, how can I do without frames...?
How do you poulate a DIV from a php file or function for example?
Of course I have my own ideas, but I want to know how others do it :-)
( Sometime soon I'll rebuild the site according to Practical Web 2.0 Applications With PHP. OOP,MVC etc... But I'll have to release a site before that...)
>Please provide some simple, conceptual snippets!
Or better yet, a site that explains the integration process!
If you know PHP, you know that it can send any HTML to a web browser that you want -- even an entire HTML page can be written totally in PHP -- so sending code to a DIV is as simple as that below --

In other words, construct an HTML page as you want it to look, change the extension to .PHP, and use the
<?php   php conditional tests here ?>   (i.e. the angle bracket ? to delimit the PHP sections)
to allow for variable content, as MMDeveloper showed above.

Once you realize that a PHP file and an HTML file are essentially the same, it becomes incredibly simple.
echo "<DIV id='" . $key . "'>\n   <TR>\n";
echo "<TD width='60' bgcolor='f8f8f8' class='text' id='key1" . $key . "'>"

Open in new window

www.tizag.com/phpT/examples/formex.php/
ww.onlamp.com/pub/a/php/2001/05/03/php_foundations.html
mgiseverything.co.uk/2008/06/06/php-html-templates/
www.faqs.org/docs/Linux-HOWTO/PHP-HOWTO.html
video.about.com/php/Using-PHP-With-HTML.htm

some links that I hope are not too simplistic for you.
Well I think I've found an acceptable solution... What about that?
//index.php
 
<!-- DDTs here -->
 
<?
 //do some php stuff
 //select $page="mypage.php"
?>
 
 
<html>
<!-- header -->
...
 <div id="content">
   <? require($page); ?>
 </div>
 
...
<!--footer-->
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of scrathcyboy
scrathcyboy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial