PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 13th, 2003, 11:47 AM
Volitics Volitics is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Knoxville, Tennessee (U.S.A.)
Posts: 58 Volitics User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 15 sec
Reputation Power: 6
How Do I Separate The PHP From The HTML?

Below is an excerpt from a PHP script that I have been using. The entire script is kind of large and
cumbersome. This one portion of the script is long horizontally and goes off the screen to the right.

I am at a point in my programming career that I need to begin using "classes" and "templates"
so I figure that this is a good place to start.

I've got the general idea about how PHP object oriented programming works. It's just the details
for which I need more of a grasp.

Can anyone give me any ideas about how I can separate the HTML from the PHP in the below script?
In other words, I need a template for the HTML, a class for the PHP/MySQL database extraction
function, and an instance to call the whole thing.

I would appreciate any pointers about how I might get started.

PHP Code:
echo "<form method=\"post\" action=\"$PHP_SELF\">";
require_once 
"../conf/config.inc.php";
$TableName "InsuranceQuote";
$Query "SELECT * FROM $TableName";
$Result mysql_db_query ($db_info[dbname], $Query$db_connection);
echo 
"<table border=\"1\" class=\"one\" cellspacing=\"0\" cellpadding=\"5\">";
while (
$Row mysql_fetch_array($Result)){
echo 
"<tr><td><input type=\"checkbox\" name=\"Reference\" value=\"".$Row["Reference"]."\"></td><td>".$Row["Salute"]."</td><td>".$Row["FirstName"]."</td><td>".$Row["Middle"]."</td><td>".$Row["LastName"]."</td><td>".$Row["Address"]."</td><td>".$Row["City"]."</td><td>".$Row["State"]."</td><td>".$Row["Zip"]."</td><td>".$Row["DayPhone"]."</td><td>".$Row["EvePhone"]."</td><td>".$Row["MailAdd"]."</td><td>".$Row["Age"]."</td><td>".$Row["BirthYear"]."</td><td>".$Row["Gender"]."</td><td>".$Row["Tobacco"]."</td><td>".$Row["HeightFeet"]."' - ".$Row["HeightInches"]."\"</td><td>".$Row["Weight"]."</td><td>".$Row["Medication"]."</td><td>".$Row["HealthProblems"]."</td></tr>\n";
}
echo 
"<tr><td colspan=\"20\" align=\"left\"><input type=\"submit\" name=\"DeleteCancerExpense\" value=\"Click Here To Delete\"></td></tr></form>";
echo 
"</table><hr size=\"5\">"


Thanking you in advance.

Volitics

Reply With Quote
  #2  
Old July 22nd, 2003, 10:11 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
My personal suggestion on this one is to start separating php from html by dropping in and out of php so you're not echoing html. This goes a long way to avoid very long echo statements especially when there are large blocks of html.

Some people dislike this way of doing things though so I also recommend trying out other suggestions if people have them.

Reply With Quote
  #3  
Old July 22nd, 2003, 10:45 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
You might consider writing (or finding) a table generation class that'll help you keep from having to print all those cumbersome table rows and cells. As a temporary quick and dirty fix, I once wrote a table() function that took an array of arrays as an argument. Each array defines a row and its elements define table cells. It doesn't take much to split all that out and write a basic table that you've had to pass nothing but data to. Of course, with that approach, you're fairly limited in what you can do with the formatting. For my purposes, it worked fine, as I had a series of standardized tables I need to print out, and this saved me some trouble.

There are a number of template engines and classes out there already that you might look into. I don't know any references off hand (Slappy, maybe?), but it shouldn't take much digging for you to find something you can work with or learn from.

Reply With Quote
  #4  
Old July 22nd, 2003, 11:30 AM
Volitics Volitics is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Knoxville, Tennessee (U.S.A.)
Posts: 58 Volitics User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 15 sec
Reputation Power: 6
kode_monkey, dhouston.

Thank you for the help.

Best Regards,

Volitics

Reply With Quote
  #5  
Old July 23rd, 2003, 06:59 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Volitics,

You may want to look into templating systems...

There are quite a few of them... Smarty being the most popular (from what I've seen). There's also patTemplate (which I find to have an easy learning curve)...

There's an article written by Havard (Lindset) on getting started with patTemplate... You should have a look. It will have you up in moments time.
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #6  
Old July 23rd, 2003, 07:04 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
There is a thread simular to this one here ( http://forums.devshed.com/t71738/s.html ) with a good learning experience.
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > How Do I Separate The PHP From The HTML?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway