General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

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 January 20th, 2003, 08:46 PM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
HTML Templates

Well looking around at alot of other peoples coding they do so much better than me...One of the problems is I have yet to figure out how to make HTML templates like people are doing.

here is an example of what I am talking about.

PHP Code:
<html>
<
head>
<
meta http-equiv=Content-Type content=text/htmlcharset={charset}>
<
meta NAME="Author" CONTENT="">
<
title>{website_title}</title>
</
head>

<
body>

<
table width="790" align="center" border="0" cellspacing="0" cellpadding="4">

<
tr class="header">
<
td align="left" valign="middle" width="420" colspan="1">&nbsp;&nbsp;<a href="index.php"><font class="pagetitle">{website_title}</font></a></td>
<
td align="right"><br>

<
form method="post" action="index.php?action=search">Search Player&nbsp;
<
input type="text" name="playername" size="21" maxlength="40">
<
input type="submit" name="submit" value="Search">
</
form>

</
td>
</
tr>

</
table>

<
table width="790" align="center" border="0" cellspacing="0" cellpadding="2">

<
tr class="navigation">
<
td align="left" valign="middle">
Stats » <a href="index.php?action=kill_stats_totals">Kill Stats</a> :: <a href="index.php?action=zone_stats">Zone Stats</a> :: <a href="index.php?action=flag_stats">Flag Stats</a> :: <a href="index.php?action=target_stats">Target Stats</a> :: <a href="index.php?action=game_stats">Game Stats</a> :: <a href="index.php?action=weapon_stats">Weapon Stats</a> ::.
</
td>
<
td align="right" valign="middle">
Links » <a href="{squad_website}" target="_blank">{squad_name}</a> ::.
</
td>
</
tr>
</
table>

<
table width="790" align="center" border="0" cellspacing="0" cellpadding="4">

<
tr class="main">
<
td valign="top">

<
br>

<
class="title">{navigation}</p>

{
content}

<
br>
<
br>

</
td>
</
tr>

</
table>

<
table width="790" align="center" border="0" cellspacing="0" cellpadding="2">

<
tr class="navigation">
<
td align="left" valign="middle">
Powered by <a href="index.php?action=about">website</aversion 3 :: "Deep Blue (Default)" template::.
</
td>
<
td align="right" valign="middle">
<
a href="index.php?action=servers">Servers</a> :: <a href="index.php?action=medals">Medals</a> :: <a href="index.php?action=ranks">Ranks</a> ::.
</
td>
</
tr>

</
table>

</
body>
</
html


The only thing I droped out was the enbeded css...Now if you look at this on a website it looks like this.

PHP Code:
<html>
<
head>
<
meta http-equiv=Content-Type content=text/htmlcharset=windows-1252>
<
meta NAME="Author" CONTENT="">
<
title>Abit - </title>

</
head>

<
body>

<
table width="790" align="center" border="0" cellspacing="0" cellpadding="4">

<
tr class="header">
<
td align="left" valign="middle" width="420" colspan="1">&nbsp;&nbsp;<a href="index.php"><font class="pagetitle">Abit</font></a></td>
<
td align="right"><br>

<
form method="post" action="index.php?action=search">Search Player&nbsp;
<
input type="text" name="playername" size="21" maxlength="40">
<
input type="submit" name="submit" value="Search">
</
form>

</
td>
</
tr>

</
table>

<
table width="790" align="center" border="0" cellspacing="0" cellpadding="2">

<
tr class="navigation">
<
td align="left" valign="middle">
Stats » <a href="index.php?action=kill_stats_totals">Kill Stats</a> :: <a href="index.php?action=zone_stats">Zone Stats</a> :: <a href="index.php?action=flag_stats">Flag Stats</a> :: <a href="index.php?action=target_stats">Target Stats</a> :: <a href="index.php?action=game_stats">Game Stats</a> :: <a href="index.php?action=weapon_stats">Weapon Stats</a> ::.
</
td>
<
td align="right" valign="middle">
Links » <a href="./" target="_blank">Abit</a> ::.
</
td>
</
tr>
</
table>

<
table width="790" align="center" border="0" cellspacing="0" cellpadding="4">

<
tr class="main">
<
td valign="top">

<
br>

<
class="title"></p>

<
center>
<
br><br><br>
<
img src="templates/babstats.gif" border="0">
<
br><br>
</
center>


<
br>
<
br>

</
td>
</
tr>

</
table>

<
table width="790" align="center" border="0" cellspacing="0" cellpadding="2">

<
tr class="navigation">
<
td align="left" valign="middle">
Powered by <a href="index.php?action=about">website</aversion 3 :: "Deep Blue (Default)" template::.
</
td>
<
td align="right" valign="middle">
<
a href="index.php?action=servers">Servers</a> :: <a href="index.php?action=medals">Medals</a> :: <a href="index.php?action=ranks">Ranks</a> ::.
</
td>
</
tr>

</
table>


</
body>
</
html


I took the css out of this as well.

Notice were it says "{website_title}" all the things in brackets....How the heck did something get into there? Is their a tutorial on this...In all my reading I have yet to find anything.

Sorry it is so long and wide....PLEASE HELP I know this will make my life easier.
__________________
Thanks,
Attila
http://www.glorynaspiration.com
http://www.abitofthings.com

Reply With Quote
  #2  
Old January 20th, 2003, 09:00 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: 7
First, the templates are read into a scalar. From there, it is regular expressions that does the data replacing, as so ->

PHP Code:
/*****************
Read tpl into scalar
*****************/
$_tpl 'template.php';
$fp fopen$_tpl'r' );
$_dat fread$fpfilesize$_tpl ) );
fclose$fp );
clearstatcache();
/*****************
Create page
*****************/
function page_head$_dat ) {
# Your Code
}
function 
page_nav$_dat ) {
# Your Code
}
function 
page_body$_dat ) {
# Your Code
}
function 
page_foot$_dat ) {
# Your Code



For each page element, you would typically have a function to create that element. The funtion would build the element and you would use a preg_replace() to replace the tpl tag with the data that is generated from the function ->

PHP Code:
 $_dat preg_replace'/{page_nav}/'page_nav$_tpl ), $_dat );
/*******************
Or something simular
*******************/ 
__________________
~ 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
  #3  
Old January 24th, 2003, 10:33 PM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
More Questions

Ok I have messed with it but I haven't done it your sugested way. I have the pages inside a database not sure if that is the best way but it is what I have done.

here is what I have.

PHP Code:
<?
require "functions.php";
dbconnect();
banned();
member();
head ($allow);
online ($allow);
echo 
$header_code;
echo 
$online_code;
?>


My functions that I have questions about.
PHP Code:
<?
function head($allow)
{
    require 
"../conf_global.php";
    global 
$header_code;
    
dbconnect();
    
$result_head mysql_query("SELECT header_id, header_code FROM header");
    
$num_rows_head mysql_num_rows($result_head);
    while (
$row_head mysql_fetch_object($result_head))
        {
            
$header_id $row_head->header_id;
            
$header_code $row_head->header_code;
            if (
$status == 0)
                {
                    if (
$allow == 4)
                    {
                        if ( ( 
stristr$header_code'{headerlink}' ) ))
                            {
                                
$_pat "/(\{)(.*?)(\})/i";
                                
$_rep "| <a href=index.php?action=home>Home</a> | | <a href=index.php?action=rulesnregs>Rules & Regs</a> | | <a href=".$cong['forums'].">Forums</a> | | <a href=index.php?action=Admin>Admin</a> |";
                                
$header_code preg_replace$_pat$_rep$header_code );        
                            }
                    }
                    else 
                    {
                        
//The next set of code replaces the special color red
                        
if ( ( stristr$header_code'{headerlink}' ) ))
                            {
                                
$_pat "/(\{)(.*?)(\})/i";
                                
$_rep "| <a href=index.php?action=home>Home</a> | | <a href=index.php?action=rulesnregs>Rules & Regs</a> | | <a href=".$cong['forums'].">Forums</a> |";
                                
$header_code preg_replace$_pat$_rep$header_code );        
                            }
                
                    }
                }
        }
        return;
}
?>


This code in the Function.
PHP Code:
 $_rep "| <a href=index.php?action=home>Home</a> | | <a href=index.php?action=rulesnregs>Rules & Regs</a> | | <a href=".$cong['forums'].">Forums</a> | | <a href=index.php?action=Admin>Admin</a> |" 


Is actually inside a database for all the links. How do I make it cycle through to the end of the database pasting each individual link? I beleive I have to put it into an array but not sure how to read my database to an array.

here is the html file.
PHP Code:
<table class="maintables" width="100%" border="0"  bordercolor="" cellspacing="0" cellpadding="0">
  <
tr
    <
td  height="45" valign="bottom"><div align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <
tr
    <
td WIDTH="25%"><div align="center"><img src="../images/squadportal.jpg" width="994" height="166"></div></td>
  </
tr>
</
table>
<
table  align="left" width="100%" border="0" cellspacing="0" cellpadding="0">
  <
tr
    <
td align="center"><font size="-1">{headerlink}</font></td>
  </
tr>
</
table></div></td>
  </
tr>
</
table


If I put {headerlink} in the html multiple times it only replaces the one value. So how do I do this.

Hope this makes sence to someone so I can get some help.

Reply With Quote
  #4  
Old January 24th, 2003, 11:44 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: 7
Well, thats alot of code to look through. You want to first grab all of the HTML out of the database, bind it to one scalar instance (not array) and do the preg_replace() on the one block. If you do the preg_replace() on the one block and do not include an int LIMIT for the preg_replace(), it will replace all instances with the replacement.

Is that what you are looking for - I am not following your post to much...?

EDIT:::
How do you have your DB setup. Do you have a table with your template and each field holds a certain html block of code? Or do you have a table for each block? How is the structure, post it so we can see....

Reply With Quote
  #5  
Old January 25th, 2003, 03:56 AM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
As of now I was creating a table for 1 piece of code. Then echoing them to the webpage. Not sure if that is the correct way...I am going to change it to the page being all in one table Would like to be able to skin things so what would be the best way...

Sorry after hours of work I figured out the other problem!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > HTML Templates


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