Sample> Db Showrecords Hook2

<?php

// include TPLN
include('TPLN/TPLN.php');

$TPLN = new TPLN;
$TPLN->open('Db_showrecords_hook2.html');

$TPLN->dbConnect();
$TPLN->setUrl('?'); // optional take current page by default
$TPLN->showRecords('SELECT * FROM Country ORDER BY RAND()'10'hookData');


// you can hook data before parsing
$Counter 0;
function 
hookData($row)
{
    global 
$TPLN$Counter;

    
$row['tr'] = '';
    
$row['tr_end'] = '';
    if(
$Counter == 0)
    {
        
$row['tr'] = '<tr>';
    }
    elseif(
$Counter == 1)
    {
        
$row['tr_end'] = '</tr>';
        
$Counter = -1// on reincrement en bas
    
}
    
$Counter++;

    
// store resulset index
    
$qID $TPLN->getQueryID();

    
// ATTENTION !!
    // you can make a subquery but it is a sample just to see in action !
    
$sql "SELECT Language FROM CountryLanguage WHERE CountryCode = '{$row['Code']}'";
    
$TPLN->DoQuery($sql);

    
$langs = array();
    while(
$row2 $TPLN->DBFetch())
        
$langs[] = $row2['Language'];

    
$row['Language'] = join(', '$langs); // create variable count before parsing
    
$row['Count'] = count($langs); // create variable count before parsing

    // replace on first resultset
    
$TPLN->setQueryID($qID);


    return 
$row;
}

$TPLN->dbClose();

$TPLN->write();




?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Db showresults hook</title>
    <link href="../style.css" rel="stylesheet" type="text/css" />
</head>

<body>

<h1>Random list of language by countries:</h1>

<bloc::data>

    <table cellpadding="3" cellspacing="1">

    <bloc::loop>
    {tr}
    <td bgcolor="#ffffff" valign="top">
        <h2>{Name} ({Count})</h2>
        {Language}<br>
    </td>
    {tr_end}
    </bloc::loop>

    </table>

    <bloc::norecord>
        No record found
    </bloc::norecord>

</bloc::data>

<br>
<br>
{_Logo}<font size="1"> in {_Chrono} s<br>
Queries executed: {_QueryCount}</font>

</body>
</html>