views:

189

answers:

2

I want to display a table in a Zend Form. For this i used blow lines

<?php 
    echo $this->form. $this->partial("staff/medicalTable.phtml");
?>

in application/views/scripts/medical/index.phtml It works fine. But now I want to display a this table in a Zend Form using an array. For this i create an array like:

<?php

/**
 * Array contain Table Column Name and Column records.
 */
    $table = array("columnName" => array("Date","Type","Comment"),
      "columnVariables" => array("1/1/09","Hepatites A","Ok"));
?>

And now how could i display my table as defined in above array, so that i could get the same result as before when there was no array for Table.

I also test http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.partial but fail to get their points

HELLO ;-> I have got some progress. but it is only for one table, the code is:

form. $this->partial("students/lunchinfoTable.phtml", array("columnName1" => "Date Enrolled", "columnName2" => "Date Canceled", "columnName3" => "Comment") ); ?>

and in my phtml file i wrote :


escape($this->columnName1);?> escape($this->columnName2);?> escape($this->columnName3);?>

But i need to apply it for many tables as i could. ie: i want to create some generic code so that i just only pass Table fields name and their values for these fields and then it display the table with passed fields.

A: 

Try this:

<table>
 <thead>
  <tr>
   <? foreach(array_keys($this->data[0]) as $column) { ?>
   <th><?=$this->escape($column);?></th>
   <? } ?>
  </tr>
 </thead>
 <tbody>
  <? foreach($this->data as $row) { ?>
  <tr>
   <? foreach($row as $value) { ?>
   <td><?=$this->escape($value);?></td>
   <? } ?>
  </tr>
  <? } ?>
 </tbody>
</table>

I assume that for all rows the array keys are same. If that's not always the case you could pass in a columns array and only output the columns based on that array.

smack0007
I have done it , but big Thankz to all
A: 
<table class="DataTable tablesorter" width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2" width="100%">  
    <thead>
        <tr>
            <th width="1%"><input type="checkbox" name="mcb"></th> 
                <?php foreach ( $this->dataStructure as $heading ) { ?> 
                    <th nowrap="yes"><?php echo $this->escape($heading['columnName']); ?></th> 
                <?php }?> 
        </tr>
    </thead>
    <tbody>
        <?php foreach ( $this->dataValues as $value ) { ?>
            <tr>                                            
                <td><input type="checkbox" name="mcb"></td>
                    <?php foreach ( $this->dataStructure as $heading ) { ?>
                    <td>
                        <?php 
                            foreach ( $heading['columnVariables'] as $var ) {
                                echo $value[$var].'&nbsp;';
                            }
                        ?>
                    </td>                                           
                    <?php }?>
            </tr> 
        <?php }?>                                       
    </tbody>
</table>