Categories > TinyButStrong general >

how to manipulate mysql-result?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: glanzlicht
Date: 2004-11-04
Time: 13:27

how to manipulate mysql-result?

Hi peeps,
I'm very new using tbs and don't know much about that atm.
We are 2 webdesigners who want to use tbs for further projects.
We're working with mysql-databases.
Our first question thinking about choosing tbs for future template system was if it's possible to manipulate mysql-results with own php-code?
Example, we've got a timestamp in one mysql-table-field and want to manipulate the timestamp-string which could be the result of the our mysql-question like 'select * from xxx' -> one of the field is a timestamp. An automatic created timestamp by mysql isn't readable for normal users and we've got a function to rebuild the timestamp-string coming out of the table-field -> Cause we are german our function rebuilds the timestamp into german format.

Is it possible to have influence on something like that and how can we do that?

Our test-tpl-file:

<html>
<head>

</head>

<body>
<table>

<tr><td></td></tr>
<tr>

<td><font></font></td><td><font>[blk1.alter;]</font></td><td><font>[blk1.geschlecht;]</font></td>

</tr>


</table>
</body>

</html>



Our test-php-file:

<?php
include_once("../db_connection/db_connection.php");

include_once('tbs_class.php');
$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('variablen_ersetzen.tpl') ;

$TBS->MergeBlock('blk1','mysql','SELECT * FROM template') ;

mysql_close($db) ;
$TBS->Show() ;


?>


Any way to include own php-code or functions to manipulate the mysql-questions or whats the results of that?

Cause manipulation of mysql-reasults is very important for our work it's one of our first point we have to know before we choosing a template-system like tbs for further projects.
At the moment we are a bit confused by all the possiblities named in manual and we need a quick answer if it's possible with tbs.

thanx in advance

glanzlicht
By: Skrol29
Date: 2004-11-04
Time: 16:08

Re: how to manipulate mysql-result?

Hi Glanzlicht,

There are several ways to manipulate the data between the table and the display result.

- You can use parameter 'onsection' on a block to modify the record being merged using a user Php function.

- You can use parameter 'onformat' on a field to modify the value being merged using a user Php function.

- You can use parameters 'frm','max',... (see summary at the end of the manual)  to change the display of a specific field.
In you case, parameter 'frm' can display a Unix TimeStamp or a MySQL DateTime value as date with your own format. But MySQL TimeStamp are not recognized unless you manipulate the string.
(see the examples in line for parameter 'frm').

- You can read the data and save it into a Php Array, then modifiy the Array, and merge the Array with TBS (the Smarty way).

- And of course, you can use the native Database functions to make the query returning arranged data.
By: glanzlicht
Date: 2004-11-09
Time: 12:14

Re: how to manipulate mysql-result?

Thanx Skrol29 for help,
I've tried a lot in the last days but without any result.
It seems that there is no effect when I include a self written function.

- Ok, this is the mysql-table I've created:

<img src="www.netzkompakt.de/sonstiges/andreas/tinybutstrong/tbs_table.jpg">



- This is my tpl-file:

<html>
<head>

</head>

<body>
<table>

<tr><td></td></tr>
<tr>
<td><font></font></td><td><font>[blk1.alter;]</font></td><td><font>[blk1.geschlecht;onsection=showme]</font></td>
</tr>
</table>
</body>

</html>


- This is my php-file:

<?php
include_once("../config/config.inc.php");

include_once('tbs_class.php');

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('variablen_ersetzen.tpl') ;

$TBS->MergeBlock('blk1','mysql','SELECT * FROM template') ;

mysql_close($db) ;
$TBS->Show() ;


function showme($BlockName,&$CurrRec,&$DetailSrc,$RecNum)
{

if ($BlockName) echo "$CurrRec[0]";
echo "bla";

}

?>



As you can see I going to include the function showme which only should give out the string 'bla' if $BlockName exists.
In the html-code I've added 'onsection=showme'.
I've tried a lot of other things that the functions showme should give out, e.g. echo "$CurrRec";, echo "$DetailSrc"; or echo "$RecNum"; , but without any result!

- The result always is

<img src="www.netzkompakt.de/sonstiges/andreas/tinybutstrong/tbs_result.jpg">


It seems that the function doesn't have any effect to the result.
I think it's a beginner fault I do but what's wrong?
How will I be able to manipulate e.g. 'männlich'?
With my function 'showme' I actually expected something like 'männlichbla' -> männlich, cause it's in the table at first row -> bla, cause it's in the function echo "bla";


Mh, would be absolutely nice if you could give me a tip whats mainly wrong, I think I havn't understood the principle.


thanx

glanzlicht
By: glanzlicht
Date: 2004-11-09
Time: 12:19

Re: how to manipulate mysql-result?

Ups, sorry 2 things wrong in my last post:
1. Is there any way to integrate pictures in a post? img-tags doesn't work ;-)

2. My description of the function 'showme' is wrong. The function generally should give out 'bla' and not only if $BlockName exists, sorry, it's because I've changed the function a lot. This is why I've descripted it the wrong way *gg*
By: Skrol29
Date: 2004-11-09
Time: 14:11

Re: how to manipulate mysql-result?

Hello Glanzlicht,

Your block definition is not correct, that's why it doesn't work.
You must define the block bound using "block=..." somewhere.
If you don't, then TBS will merge only the first record with no possible block parameter (because of no block definition). That's what you've done and that's why 'onsection' is ignored.

Your template should be:
<html>
<head></head>
<body>
<table>
  <tr><td></td></tr>
  <tr>
    <td><font></font></td>
    <td><font>[blk1.alter]</font></td>
    <td><font>[blk1.geschlecht;block=tr;onsection=showme]</font></td>
  </tr>
</table>

</body>
</html>

By the way, extra ";" at the end of the TBS tag are useless. ";" is only a separator.

There is an example at the Example Page that fits with what you're trying to do. It is called "event functions".

Sorry, this forum doesn't support pictures (yet) but I've seen yours.
By: glanzlicht
Date: 2004-11-09
Time: 15:22

Re: how to manipulate mysql-result?

Ok, thanx Skrol for help again,
yeah, I saw the example and thought everything should be nearly similar, except that you've used an array in this example.
Yes, I deleted block=tr cause I thought it means that every single mysql-record will appear in html-table by adding as many tr's as nescessary to express the whole mysql-result. And I only wanted the first record of the table.
Ok, I will try with block=tr again and hopefully learn the whole principle as fast as it can go. ;-)

thanx again, I fear I will be back with more questions to other aspects next time  ;-)

great help

glanzlicht