-2

I have this code which prints a table taken from a search query and I want to enumerate them using PHP. I'm trying a for loop but unsuccessfully. Can anyone please help me?

<table id="students">
    <?php

    $iterator = new CDataProviderIterator($dataProvider);

          //echo count($iterator);

          echo '<thead>';

            echo '<tr>';
            echo '<th>'.Yii::t('default', 'Last Name').'</th>';
            echo '<th>'.Yii::t('default', 'First Name').'</th>';
            echo '<th>'.Yii::t('default', 'Description').'</th>';
            echo '<th>'.Yii::t('default', 'Debit').'</th>';
            echo '<th>'.Yii::t('default', 'Credit').'</th>';
            echo '<th>'.Yii::t('default', 'Date').'</th>';
            echo '<th>'.Yii::t('default', 'Trans number').'</th>';
            echo '</tr>' ; 
              echo '</thead>';
         echo '<tfoot>';
                echo '<tr>';
                    echo '<td>'.Yii::t('default', 'Page Total').'</td>';
                echo '<td>'."".'</td>';
                echo '<td>'."".'</td>';
                echo '<td>'."".'</td>';
                echo '<td>'."".'</td>';
                echo '<td>'."".'</td>';
                echo '<td>'."".'</td>';

            echo '</tr>';
      echo '</tfoot>';


         $sumdebit=0;
         $sumcredit=0;
        foreach($iterator as $rec) {

          $sumdebit+=$rec['debit'];
          $sumcredit+=$rec['credit'];


          echo '<tbody>';
            echo '<tr>'; 
            $count=0;
          for ($i=0;$i<=40;$i++){
          $count+=$i;

              echo '<td>'.$count; '</td>';
        echo '<td>'.$rec['student']['lastname']; '</td>';
        echo '<td>'.$rec['student']['firstname'];'</td>';
        echo '<td>'.$rec['transtype']['description']; '</td>';
        echo '<td align="right">'.$rec['debit']; '</td>';
        echo '<td align="right">'.$rec['credit']; '</td>';
        echo '<td>'.$rec['transdate']; '</td>';
        echo '<td>'.$rec['transnumber']; '</td>'; 
        }
        echo '</tr>';
      echo '</tbody>'; 



    }

        echo '<tr>';
           echo '<td>'.Yii::t('default', 'Total').'</td>';
           echo '<td>'."".'</td>';
           echo '<td>'."".'</td>';
           echo '<td align="right">'.$sumdebit;'</td>';
           echo '<td align="right">'.$sumcredit;'</td>';
           echo '<td>'."".'</td>';
           echo '<td>'."".'</td>';

        echo '</tr>';

    ?>

    </table>

My problem is that I want to enumerate the table rows, also I'm not very familiar with the syntax and all of this. I'm trying to make it work in Yii. which I'm not very familiar also. So the problem is I want to put numbers in front of every row. For example I have 20 table rows and I want to start counting and enumerate them. e.g. 1. George Cat 2. Tom Dog 3. John Bird etc..

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
thr
  • 35
  • 1
  • 9

1 Answers1

0

Your question is unclear, you do not state what your actual problem is.

Therefore we can only guess...

[...]
echo '<tbody>';
  echo '<tr>'; 
    for ($i=0;$i<=40;$i++) {
      echo '<td>'.$i.'</td>';
[...]

You probably received a syntax error which you apparently either didn't see (look into the error log files!) or simply ignored. At least you did not post it here though it probably exactly points out what the issue is...

arkascha
  • 41,620
  • 7
  • 58
  • 90