Visualizzazione dei risultati da 1 a 8 su 8

Visualizzazione discussione

  1. #3
    Utente di HTML.it L'avatar di boots
    Registrato dal
    Oct 2012
    Messaggi
    1,626
    Credo ti basti parametrizzare la funzione:
    Codice PHP:
    function get_table($q$headers$fields){
       
    $testo "...";
       foreach(
    $headers as $header){
          
    $testo .= "<th>$header</th>";
       }
       
    $testo .= '...';
       while(
    $row = ...){
          
    $testo .= '<tr>';
          foreach(
    $fields as $field){
             
    $testo .= '<td>'.$row->$field .'</td>';
          }
          
    $testo .= '</tr>';
       }
       echo 
    $testo;

    Cmq, perchè non sfrutti l'essere un template engine di php ?
    Es. potresti crearti un file "table.tpl" con dentro il codice di sopra, senza la variabile $testo:
    codice:
    <table...>
       <tr>
      <?php foreach($headers as $header): ?>
          <th><?php echo $header ?></th>
      <?php endforeach ?>
      </tr>
      ...tutto il resto ..
    </table>
    nella tua funzione get_table
    Codice PHP:
    function get_table($q$headers$fields){
        
    ob_start();
        include(
    'table.tpl');
        return 
    ob_get_clean(); // oppure echo

    e se poi ci rifletti bene, potresti renderla generica (basta che passi i parametri in modo congruo) e renderizzare qualunque cosa perchè poi cosa e come visualizzare sta nel tpl
    Ultima modifica di boots; 10-04-2018 a 12:37

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.