Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old April 26th, 2004, 03:21 AM
Poleh Poleh is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Wellington, New Zealand
Posts: 2 Poleh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP Templating engine by Timothy Boronczyk

Hi Timothy

first off, great little tut, I like it and reckon it will be very usefull. I have been looking for an effective way to separate my code from my content for ages now, and there seems to be no one set way of doing that!

I have a scenarion that I wonder if you could help me with.

I essentially have a page (results.tpl) that is a table, with two columns and two rows. The first row is headings (id, name) and the second row is a tag/macro to be replaced with the results of a database call (returning id, name funnily enuff!)

<table>
<tr>
<td>id</td>
<td>name</td>
</tr>
<td>
{rs}
</table>

Now, obviously the {rs} - recordset is a loop that runs through a series of mysql_fetch_assoc calls to get the data ... that data itself should be "templatable" i.e., I want a template for the results page that I can initiate from your template engine.

Can you point me the right direction on this? I know you said that the engine supports nesting templates, how is this done, because I imagine nesting is the solution to what I am trying to do here ...

Any help would be appreciated !

Tnx in advance.

Reply With Quote
  #2  
Old May 1st, 2004, 10:35 PM
bluephoenix's Avatar
bluephoenix bluephoenix is offline
Levelheaded Curmudgeon
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Syracuse, NY
Posts: 507 bluephoenix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 13 m 2 sec
Reputation Power: 2
Send a message via AIM to bluephoenix
RE: PHP Templating engine by Timothy Boronczyk

This is how I've done it...

results.php
php Code:
Original - php Code
  1. <?php
  2.     include "lib/class.Page.php";
  3.     $p = new Page("results.tpl");
  4.     $p->replace_tags(array(
  5.         "RS" => "table-rows.php"));
  6.     $p->output();
  7. ?>


results.tpl
Code:
<table>
    <tr><td>id</td><td>name</td></tr>
    {RS}
  </table>


table-rows.php
php Code:
Original - php Code
  1. <?php
  2.     $db = mysql_connect("localhost",
  3.           "user", "password");
  4.     mysql_select_db("my_db");
  5.     $result = mysql_query("select
  6.           id, names from my_table");
  7.     while (list($id, $name)
  8.           = mysql_fetch_row($result))
  9.         echo "<tr><td>$id</td>
  10.               <td>$name</td></tr>";
  11. ?>


Best of luck,

-Tim

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > PHP Templating engine by Timothy Boronczyk


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 4 hosted by Hostway