sto facendo in questo modo.
nella pagina template.function.php creo la funzione, che richiamerò all'interno di altre funzioni
Codice PHP:
function HTML_TABLE($arrTH,$caption){ $testo ="<table class='tb_zone' summary='Questa tabella indica ".$caption."'> <caption>".$caption."</caption> <tr>"; for($i=0;$i<=count($arrTH)-1;$i++){ $testo .="<th id='header".$i."' style='width:25%'>".$arrTH[$i]."</th>"; } $testo .="</tr>"; return $testo;}
// e poi
function get_table_25($q,$arrTH,$caption){ $last = array(); $count = ""; echo HTML_TABLE($arrTH,$caption); $testo = ""; while ($rows = mysqli_fetch_object($q)){/*...*/} $testo.= "</table>"; echo $testo;}
Invece nella function.class.php creo l'array $arrTH e la variabile $caption da passare
Codice PHP:
public function get_consulenti_collaboratori($request=0){ if($this->tableExists($request)!==false){ $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");
$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)) { $arrTH = array("Nominativo","Ruolo","CV","Compensi","Scadenza"); $caption = "consulenze esterne"; return $table_name($query,$arrTH,$caption); } mysqli_free_result($query); } else{ echo report_error(); } }}
Sembra che cosi funziona.
Domanda: è il metodo migliore o ce ne sono altri?
Grazie come sempre.