0

Ok i cant see whats wrong in this function, all array values work fine and the rest not, for some reason i cant see, any help will be apreciated.

<?php
                //formato do array $colunas ['Nome do Header'] => array('tipo de formatação a retornar','titulo da coluna no banco','substring' , 'mostrar padrao', 'largura da coluna')
                $colunas = array(
                '#'=>array('nenhuma','contagem',0,0,0),
                'Id'=>array('nenhuma','id',0,0,0),
                'Nome do Cliente'=>array('nenhuma','nome',0,0,0),
                );
                renderdatatable('SELECT id,nome FROM #__metafacil_clientes', $colunas); ?>

This is the call of the function that ill paste below

function renderdatatable($query, $colunas) {

$keys = array_keys($colunas);
$qtde_colunas = count($keys);
$db = JFactory::getDBO();
$db->setQuery($query);
$campos = $db->loadAssocList();

if (empty($campos)) {
    //retornar um template inicial para o cliente...
} else {
    echo '<table class="table table-striped table-bordered dTableR"><thead><tr>';
    for ($c=1;$c<=$qtde_colunas;$c++) {
        $d = $c-1;
        echo '<th>'.$keys[$d].'</th>';
    }
    echo '</tr></thead><tbody>';
    $numerolinha = 1;
    foreach ($campos as $campo){
        echo '<tr>';
        for($i=1;$i<=$qtde_colunas;$i++) {
            echo '<td>';
            //usamos o $l = $i-1 para acessar o vetor contendo o tipo de campo e switch para formatá-lo onde $campo e a linha retornada pela consulta com chave de array alfanumerico
            $l = $i-1;
            $chavecoluna = $keys[$l];
            $coluna = $colunas[$chavecoluna][1];
            switch ($coluna) {
                case 'imagem':
                    $value = formata_imagem($campo[$coluna]);
                    break;
                case 'contagem':
                    $value = $numerolinha;
                default:
                    $value = $campo[$coluna];
            }
            //fecha a celula
            echo $value;
            echo '</td>';
        }
        echo '</tr>';
        $numerolinha = $numerolinha+1;
    }
    echo '</tbody></table>';
}

}

This function have the objective of render a table, as my system will need a lot of different tables, i'm pardonizing this function so i dont need to write the query every single time a page is loaded

All is working fine except the $numerolinha variable that is not showing in the array for reason i dont know....why is not working any help?

its a joomla function by the way

6
  • in your switch case any of your $coluna equals to 'contagem'?
    – bagonyi
    Dec 1, 2013 at 0:45
  • Lemme perform a check Dec 1, 2013 at 0:47
  • Shoulb be only the $colunas['#'][1] as you can see the loop Dec 1, 2013 at 0:52
  • can you print_r() or var_dump() the $campos array and paste it here?
    – bagonyi
    Dec 1, 2013 at 0:56
  • Array ( [0] => Array ( [id] => 1 [nome] => Paulo José ) [1] => Array ( [id] => 2 [nome] => Pedro Augusto ) [2] => Array ( [id] => 3 [nome] => CANAFIH ) ) Dec 1, 2013 at 0:58

1 Answer 1

0

The problem was the missing break just below this line

$value = $numerolinha;

Thanks bagovyi for your support!!

1
  • Ah, didn't catch that one! Nice :)
    – bagonyi
    Dec 1, 2013 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.