Buon giorno.
Ho una classe con funzioni che interagiscono con il DB.
Fin'ora, ho sempre incluso l'HTML all'interno di queste funzioni, per visualizzarne il risultato.
Ora vorrei, lavorare in maniera diversa questi dati.
Ho due pagine, function.class.php e template.function.php.
Nella prima ho:
Codice PHP:
public function get_organizzazione($request=0){ $query= $this->connect->query("SELECT a.* FROM ".$GLOBALS['table']." as a INNER JOIN ".tb_menu." as b ON a.id_menu_p = b.id WHERE a.id_menu_s=".$request." AND ".$this->http_host()."=1 ORDER BY a.id_posizione");
$this->conta = mysqli_num_rows($query); # vado ad interagire con la funzione in template.function.php get_table_25, get_table_2 etc etc $table_name = "get_table_$request"; if ($this->conta > 0) { # controllo se in template.function.php è presente la funzione che voglio richiamare if (function_exists($table_name)) { return $table_name($query); } mysqli_free_result($query); } else{ echo report_error(); } }
Invece nella template.function.php, richiamo la funzione passandogli $query
Codice PHP:
function get_table_25($q){ $testo ="<table class='tb_zone' summary='Questa tabella indica telefono e posta elettronica'> <caption>Questa tabella indica telefono e posta elettronica.</caption> <tr> <th id='header1'>Struttura aziendale</th> <th id='header2'>Telefono</th> <th id='header3'>Indirizzi (e-mail,pec)</th> </tr>"; while ($rows = mysqli_fetch_object($q)) { $testo.= "<tr> <td headers='header1'>".$rows->struttura_aziendale."</td> <td headers='header2'>".$rows->tel1."</td> <td headers='header3'>".$rows->email."</td>
</tr>"; $count++; } $testo.= "</table>"; echo $testo;}
Cosa voglio ottenere?
Vorrei far in modo di riutilizzare la struttura di questa tabella, per altre funzioni, senza dover creare N tabelle HTML.
Capire, come poter aggiungere o rimuovere i tag <th> e <td> a seconda della necessità.
Cioè, avere una tabella HTML dinamica.
E' possibile?
Grazie mille.