theme_table

3 contenuti / 0 new
Ultimo contenuto
theme_table

ciao a tutti,
volevo utilizzare, se possibile, theme_table per generare una tabella all'interno delle cui celle abbia dei campi di testo del tipo <input type="text" ... />.
l'attributo value di questi campi di testo dovrebbe avere come valore predefinito un valore preso da una tabella di mysql.
la funzione seguente stampa una tabella ma nel ciclo while ($row = db_fetch_object($result)) {...} vorrei stampare questi campi di testo (ad esempio: <input type="nome[]" value="valore_che_c'è_nel_campo_della_tabella_mysql" />).
come è possibile farlo?

<?php
function theme_mio_modulo_table() {
   
// Table header. Used as tablesort default
 
$header = array(
    array(
'data' => t('Campo 1'), 'field' => 'tabella.campo1', 'sort' => 'asc'),
    array(
'data' => t('Campo 1'), 'field' => 'tabella.campo2'),
    array(
'data' => t('Campo 3'), 'field' => 'tabella.campo3')
  );
   
$query = 'SELECT tabella.* FROM {tabella}';
   
$result = db_query($query);
    if (
db_num_rows($result) == 0) {
       
$rows[] = array(array('data' => t('Nessuna dato inserito.'), 'colspan' => 3));
    }
    else {
       
$rows = array();
        while (
$row = db_fetch_object($result)) {
           
$rows[] = array($row->campo1, $row->campo2, $row->campo3);
        }
    }
   
$output = theme('table', $header, $rows);
    return
$output;
}
?>

mi sono dimenticato di dire che uso drupal 5

leggendo meglio su api.drupal.org la documentazione di theme_table penso di aver trovato una possibile soluzione. ho sostituito la seguente parte:

<?php
$rows
[] = array($row->field1, $row->field2, $row->field3);
?>

con questa:
<?php
$rows
[] = array(
  array(
'data' => '<input type="text" name="test1" value="'.$row->field1.'" />'),
  array(
'data' => '<input type="text" name="test2" value="'.$row->field2.'"  />'),
  array(
'data' => '<input type="text" name="test3" value="'.$row->field3.'"  />')
);
?>