Categories > TinyButStrong general >

The first Template Engine...

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Mankiy
Date: 2003-06-30
Time: 06:06

The first Template Engine...

This is the First Template Engine I've seen working for me for mysql and all the stuff Im needing done........

theres jsut one problem, for me........

I need it to do this:

                     MAIN TITLE
SUB_TITLE
SUB_TITLE
                     MAIN_TITLE
SUB_TITLE
SUB_TITLE






but its doing this:

                         MAIN TITLE
                         MAIN_TITLE
SUB_TITLE
SUB_TITLE
SUB_TITLE
SUB_TITLE



Is there a way to do that atm?

if so, that would be GREAT, ty :)
By: Mankiy
Date: 2003-06-30
Time: 06:12

Re: The first Template Engine...

and sorry if this is already explained somewhere, but Im REALLY busy and dont have much time to go browsing, I have 4 projects, 3 of them I have to complete this wk, and its really a hassle 0_o
By: Skrol29
Date: 2003-06-30
Time: 09:07

Re: The first Template Engine...

Hello Manki,

I'm afraid I don't undestand your problem.
Could you give more detail ?
By: Pirjo Posio
Date: 2003-06-30
Time: 10:33

Re: The first Template Engine...

Is this problem solved in Short TBS Examples by example named Headers?
By: Mankiy
Date: 2003-06-30
Time: 18:24

Re: The first Template Engine...

hmmm,  Im getting data out of two tables.....

hyper_main and hyper_sub

Hyper main conatins the main _name;
hyper_sub contains sub_name, sub_description, mods, last_post, and last_date;


I want it to show the main_name from hyper_main and then the sub_names that go with it.

there are two main_names and 6 sub_names, 2 sub_names to each main_name


get what im saying now?
By: Mankiy
Date: 2003-07-01
Time: 01:28

Re: The first Template Engine...

do you get that explination?

if you dont, im gonna have to start being more precise 0_o
By: Skrol29
Date: 2003-07-01
Time: 01:44

Re: The first Template Engine...

Yes please.
I can't see what is your query.
Is there one or two ?

If there is only one query, you can make a header group in your block.
Just as said Pirjo.
By: Mankiy
Date: 2003-07-01
Time: 01:55

Re: The first Template Engine...

heres the current code for the Template, the PHP script, and a screenshot of what its doing....

TEMPLATE:
<html>
<head>
<title> {TITLE} </title>
</head>
<body bgcolor="#FFFFFF">

<TABLE border="0" cellspacing="0" cellpadding="0" width="850">
  <TR><TD bgcolor="#898989" width="550">
    <center><font size="3"> FORUM </font></center>
</TD>
  <TD width="75" bgcolor="#898989">
    <center><font size="3"> POSTS </font></center>
</TD>
  <TD bgcolor="#898989" width="75">
    <center><font size="3"> TOPICS </font></center>
</TD>
  <TD bgcolor="#898989" width="100">
    <center><font size="3"> LAST POST </font></center>
</TD></TR>


<TR>
  <TD width="800" bgcolor="#C9C9C9">
    <center><b> {main.main_name;block=tr} </b></center>
</TD>
</TR>



          <TR><TD bgcolor="#C5C5C5" width="550">
             <a href=""> {sub.sub_name;block=tr} </a>
             <br> {sub.sub_description}
             <br> {sub.moderators}</TD>


                       <TD bgcolor="#C3C3C3" width="75">
                          <center><font size="2"> {c1.count} </font></center>
                       </TD>
                       <TD bgcolor="#C5C5C5" width="75">
                          <center><font size="2"> {c2.count} </font></center>
                       </TD>


           <TD bgcolor="#C5C5C5" width="100">
              <center><font size="2"> {sub.last_post}
              <br> {sub.last_date} </font></center>
           </TD>
        </TR>
    </TABLE>

</body>
</html>






PHP:
<?php
   require("config.php");
   require_once("tpl_class.php");

$PAGE = new tpl_class;
$PAGE->LoadTemplate("index.tpl");
$PAGE->MergeField("TITLE", "Hyper");


// session start and check
session_start();
$username = $_SESSION["username"];
$password = $_SESSION["password"];
$error = mysql_error();


$PAGE->MergeBlock("main", "mysql", "SELECT * FROM hyper_main");
$PAGE->MergeBlock("sub", "mysql", "SELECT * FROM hyper_sub");


$result = @mysql_query("SELECT id FROM hyper_sub");
WHILE ( $row = mysql_fetch_array($result) ) {
  $sid = $row[sub_ID];
$PAGE->MergeBlock("c1", "mysql", "SELECT count(*) FROM hyper_posts AS amount WHERE sub_ID='$sid'");
$PAGE->MergeBlock("c2", "mysql", "SELECT count(*) FROM hyperbb_topics AS amount WHERE sub_ID='$sid'");
}

$PAGE->Show();

exit();
mysql_close();
?>

and here is the screenshot:
http://members.lycos.co.uk/clanx/screen.jpg


Where you see the light table rows above, those are the main_names


the 6 rows below that are the sub_names...

so here is how i want it to go:

main_name
sub_name
sub_name

main_name
sub_name
sub_name


does that help any?
By: Skrol29
Date: 2003-07-01
Time: 10:49

Re: The first Template Engine...

Hello Mankiy,

Yes, its perfect clear now.

There is two ways to do what you want.
The simpliest way is to use headers.

First of all, you have to 'link' somehow your main and sub data in order to display a main and its subs bellow.

PHP:
$sql = "SELECT main_name, sub_name, sub_description, moderators, COUNT(p.*) as hp_cnt FROM  hyper_main AS m INNER JOIN hyper_sub AS s ON (m.main_id=s.main_id) INNER JOIN hyper_posts AS p ON (p.sub_id=p.sub_id) GROUP BY main_name, sub_name, sub_description, moderators, ORDER BY main_name, sub_name" ;

$PAGE->MergeBlock("global", "mysql", $sql);

Then you have to change your template in order to have only one block. You can define one block on several rows using the parameter 'extend'.



The other way is to link you different block using clones blocks.
Clones blocks enables you to pass parameters to the SQL statement for each cloned blocks you have.

First to have to extend the 'main' block in order to have it nesting the 'sub' and 'c1' blocks (see the 'extend' parameter).
Then you have to merge the 'main' block. This way 'sub' and 'c1' are cloned.
Then use clone parameters (see cloned blocks) to merge 'sub' and 'c1' blocks linked to each main_id.


By: Mankiy
Date: 2003-07-01
Time: 22:26

Re: The first Template Engine...

im not really understanding the clone blocks, I looked into it in the tbs_us_help.html file, but it jsut confused me more, that file always does 0_o
By: Mankiy
Date: 2003-07-03
Time: 04:30

Re: The first Template Engine...

I just dont get how they are used, i tried several ways, and none seem to work 0_o
By: Skrol29
Date: 2003-07-03
Time: 09:44

Re: The first Template Engine...

Hummmmm
You seem to be unluky with TBS.
If it's bot confidential, could you send you template + code + tables structure so I can try them on my PC.
By: Mankiy
Date: 2003-07-03
Time: 20:15

Re: The first Template Engine...

send them thru what?

Its not confidential, its just forum code, i send it thru ur mail...
By: Skrol29
Date: 2003-07-03
Time: 20:19

Re: The first Template Engine...

Yes, by email.
It's on the left of this message.
<- here
(skrol29@freesurf.fr)
By: Mankiy
Date: 2003-07-03
Time: 20:27

Re: The first Template Engine...

wait, i jsut post it here....

no sense in dealing with mail....

here is the Template Code (original)
<html>
<head>
<title> {TITLE} </title>
</head>
<body bgcolor="#FFFFFF">

<TABLE border="0" cellspacing="0" cellpadding="0" width="850">
  <TR><TD bgcolor="#898989" width="550">
    <center><font size="3"> FORUM </font></center>
</TD>
  <TD width="75" bgcolor="#898989">
    <center><font size="3"> POSTS </font></center>
</TD>
  <TD bgcolor="#898989" width="75">
    <center><font size="3"> TOPICS </font></center>
</TD>
  <TD bgcolor="#898989" width="100">
    <center><font size="3"> LAST POST </font></center>
</TD></TR>

{main;block=begin}
<TR>
  <TD width="800" bgcolor="#C9C9C9">
    <center><b> {main.main_name} </b></center>
</TD>
</TR>


         {sub;block=begin}
          <TR><TD bgcolor="#C5C5C5" width="550">
             <a href="show_topics.php?f={sub.sub_ID}">{sub.sub_name}</a>
             <br> {sub.sub_description}
             <br> {sub.moderators}</TD>


                       <TD bgcolor="#C3C3C3" width="75">
                          <center><font size="2"> {c1.count} </font></center>
                       </TD>
                       <TD bgcolor="#C5C5C5" width="75">
                          <center><font size="2"> {c2.count} </font></center>
                       </TD>


           <TD bgcolor="#C5C5C5" width="100">
              <center><font size="2"> {sub.last_post}
              <br> {sub.last_date} </font></center>
           </TD>
        </TR>
      {sub;block=end}
      {main;block=end}
    </TABLE>

</body>
</html>


PHP Code:
<?php
   require("config.php");
   require_once($clsdir."tpl_class.php");

$PAGE = new tpl_class;
$PAGE->LoadTemplate($tpldir."index.tpl");
$PAGE->MergeField("TITLE", "HyperBB");


// session start and check
session_start();
$username = $_SESSION["username"];
$password = $_SESSION["password"];
$error = mysql_error();


$PAGE->MergeBlock("main", "mysql", "SELECT * FROM hyper_main");
$PAGE->MergeBlock("sub", "mysql", "SELECT * FROM hyper_sub");


$result = @mysql_query("SELECT id FROM hyper_sub");
WHILE ( $row = mysql_fetch_array($result) ) {
  $sid = $row[sub_ID];
$PAGE->MergeBlock("c1", "mysql", "SELECT count(*) FROM hyper_posts AS amount WHERE sub_ID='$sid'");
$PAGE->MergeBlock("c2", "mysql", "SELECT count(*) FROM hyper_topics AS amount WHERE sub_ID='$sid'");
}

$PAGE->Show();

exit();
mysql_close();
?>


and the table structures:
#
# Table structure for table `hyper_main`
#

CREATE TABLE hyper_main (
  main_name varchar(50) NOT NULL default '',
  ID int(11) NOT NULL auto_increment,
  PRIMARY KEY  (ID),
  UNIQUE KEY ID (ID)
) TYPE=MyISAM;
# --------------------------------------------------------


#
# Table structure for table `hyper_posts`
#

CREATE TABLE hyper_posts (
  posted_by varchar(20) NOT NULL default '',
  topic varchar(70) NOT NULL default '',
  post_text text NOT NULL,
  post_date varchar(100) NOT NULL default '',
  topic_ID int(11) NOT NULL default '0',
  sub_ID int(11) NOT NULL default '0',
  ID int(11) NOT NULL auto_increment,
  PRIMARY KEY  (ID),
  UNIQUE KEY ID (ID)
) TYPE=MyISAM;
# --------------------------------------------------------

#
# Table structure for table `hyper_sub`
#

CREATE TABLE hyper_sub (
  sub_name varchar(50) NOT NULL default '',
  sub_description varchar(255) NOT NULL default '',
  moderators varchar(120) NOT NULL default '',
  last_post varchar(20) NOT NULL default '',
  last_date varchar(100) NOT NULL default '',
  main_ID int(11) NOT NULL default '0',
  ID int(11) NOT NULL auto_increment,
  PRIMARY KEY  (ID),
  UNIQUE KEY ID (ID)
) TYPE=MyISAM;
# --------------------------------------------------------

#
# Table structure for table `hyper_topics`
#

CREATE TABLE hyper_topics (
  posted_by varchar(20) NOT NULL default '',
  last_post varchar(20) NOT NULL default '',
  last_date varchar(100) NOT NULL default '',
  topic_name varchar(70) NOT NULL default '',
  sub_ID int(11) NOT NULL default '0',
  ID int(11) NOT NULL auto_increment,
  PRIMARY KEY  (ID),
  UNIQUE KEY ID (ID)
) TYPE=MyISAM;

there
By: Mankiy
Date: 2003-07-04
Time: 02:25

Re: The first Template Engine...

I will be gone for the Holiday weekend, i be back sunday, and ty for all the help....
By: Skrol29
Date: 2003-07-06
Time: 02:37

Re: The first Template Engine...

Hello Mankiy,

First of all, you've forgotten the
$tbs_ChrOpen = '{' ;
$tbs_ChrClose = '}' ;

I've tried your code and it goes better with the delimiter re-definition.
By: Mankiy
Date: 2003-07-07
Time: 00:41

Re: The first Template Engine...

no, I changed those also.....
By: Skrol29
Date: 2003-07-07
Time: 01:42

Re: The first Template Engine...

Hello Mankiy,

I've tried to do your page with only one query in order to use the TBS header blocks but it is not so easy because you want your page to display some info for each Sub entities.

Here is how you can do your page with clones blocks.
Clones blocks is a way to perform sub-blocks.

PHP:
<?php
   require("config.php");
   require_once("tbs_class.php");

$PAGE = new clsTinyButStrong;

$tbs_ChrOpen = '{' ;
$tbs_ChrClose = '}' ;

$PAGE->LoadTemplate("index.htm");
$PAGE->MergeField("TITLE", "Hyper");

$PAGE->MergeBlock("main", "mysql", "SELECT * FROM hyper_main");
$PAGE->MergeBlock("sub", "mysql", "SELECT * FROM hyper_sub WHERE (main_id=%p1%)");
$PAGE->MergeBlock("c1", "mysql", "SELECT count(*) as count FROM hyper_posts AS amount WHERE (sub_ID=%p1%)");
$PAGE->MergeBlock("c2", "mysql", "SELECT count(*) as count FROM hyper_topics AS amount WHERE (sub_ID=%p1%)");

$PAGE->Show();
?>

HTML:
<html>
<head>
<title> {TITLE} </title>
</head>
<body bgcolor="#FFFFFF">

<TABLE border="0" cellspacing="0" cellpadding="0" width="850">
  <TR><TD bgcolor="#898989" width="550">
    <center><font size="3"> FORUM </font></center>
</TD>
  <TD width="75" bgcolor="#898989">
    <center><font size="3"> POSTS </font></center>
</TD>
  <TD bgcolor="#898989" width="75">
    <center><font size="3"> TOPICS </font></center>
</TD>
  <TD bgcolor="#898989" width="100">
    <center><font size="3"> LAST POST </font></center>
</TD></TR>


<TR>
  <TD width="800" bgcolor="#C9C9C9">
    <center>
    <b> {main.main_name;block=tr;extend=1}</b>
    </center>
</TD>
</TR>



          <TR>
          <TD bgcolor="#C5C5C5" width="550">
             <a href=""> {sub.sub_name;block=tr;p1={main.id}} </a>
             <br>
              {sub.sub_description}
             <br> {sub.moderators}</TD>


                       <TD bgcolor="#C3C3C3" width="75">
                          <center>
                          <font size="2"> {c1.count;block=td;p1={sub.id}} </font>
                          </center>
                       </TD>
                       <TD bgcolor="#C5C5C5" width="75">
                          <center>
                          <font size="2"> {c2.count;block=td;p1={sub.id}}</font>
                          </center>
                       </TD>


           <TD bgcolor="#C5C5C5" width="100">
              <center><font size="2"> {sub.last_post}
              <br> {sub.last_date} </font></center>
           </TD>
        </TR>
    </TABLE>

</body>
</html>

By: Mankiy
Date: 2003-07-07
Time: 02:33

Re: The first Template Engine...

o!, i get how it works now :)

ty for all the help, hope i wasnt THAT much of a burden :)

and i was using the extend thing wrong also 0_o