Categories > TinyButStrong general >

mysql question

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

mysql question

if i add the tag, such as:
user_data.tpl
<html>
<head>
<title> User Data </title>
</head>
<body>
<table>
<tr><td>
{user}
</td></tr>
<tr><td>
{userpass}
</td></tr>
</table>
</body>
</html>

and the php part
<?php

require_once("tbs_class.php");
$TBS = new clsTinybutStrong;
$TBS-> LoadTemplate("user_data.tpl");

require("connect.php");
// this contains the function to connect to the db
connectdb("localhost", "dbuser", "dbpass", "dbname");

$error = mysql_error();
$result = @mysql_query("SELECT user,pass FROM members");
if (!$result) {
echo("ERROR: $error");
}

while ( $row = mysql_fetch_array($result) ) {
$user = $row[user];
$userpass = $row[pass];

$TBS-> MergeField("user", "$user");
$TBS-> MergeField("userpass", "$pass");
}
?>



I want to know if it will show it as being a new tr and td tag in html for every new user and pass

and if it doesnt, how can i get it to do that??
ty :)
By: Skrol29
Date: 2003-06-01
Time: 22:18

Re: mysql question

Hi Mankiy,

No, it won't show a new tr for each record (user) because you didn't define a block.

Here is the right code:

html>
<head>
<title> User Data </title>
</head>
<body>
<table>
<tr><td>
{b1.user;block=tr}
</td></tr>
<tr><td>
{b1.userpass}
</td></tr>
</table>
</body>
</html>

Php part:
<?php

require_once("tbs_class.php");
$tbs_ChrOpen = '{' ; //Default value is '['
$tbs_ChrClose = '}' ; //Default value is ']'

$TBS = new clsTinybutStrong;
$TBS-> LoadTemplate("user_data.tpl");

require("connect.php");
// this contains the function to connect to the db
connectdb("localhost", "dbuser", "dbpass", "dbname");

$TBS->MergeBlock('b1','mysql','SELECT user,pass FROM members') ;
$TBS->Show() ;

?>
'mysql' is a keyword that enables TinyButStrong to retrieve the default MySQL connection. YOu can replace it by $CnxId if any.
By: Mankiy
Date: 2003-06-02
Time: 00:31

Re: mysql question

i dont really understand how the block thing works, can you tell me plz?

ty :)
By: Skrol29
Date: 2003-06-02
Time: 11:54

Re: mysql question

Well, it's true that blocks are badly explained in the manual.
I had some complains about that.

But with the fresh new version, I've rewrited the block chapter.

Blocks are something usual with Template Engines.
This is usual for merge process in general.

When you need a section of your template to be repeated (in you case: a row a a table), as much time as there is records in a record source (in your case: a MySql query), then you need blocks.

A block is the section to be repeated. it is usually a row, but in some other case it can be anything else (an option for a list for example).
That why you have to define it. This can not be automatic.
In the example of my previous post, the
block is defined on the row using the parameter "block=td".

When you have defined the block, then TinyButStrong does the end of the job. It has a special function MergeBlock() that enables you to merge a defined block with a query.

I hope this will help.
Regards,


By: Mankiy
Date: 2003-06-02
Time: 22:42

Re: mysql question

it does a lot, ty :)

one more question though...

when using blocks like this: block=tr
does it repeat everything inside the tr tags?
By: Skrol29
Date: 2003-06-02
Time: 23:49

Re: mysql question

yes it does