PHP count rows from foreach loop -


i'm using "foreach" loop in php create tables mysql data

what i'm trying achieve count amount of rows being returned loop

the loop creating new tables each "machine" , fills "contracts" new rows whenever try count rows returns count tables instead of single one.

here's code:

<?php  foreach ($this->datatitle $head) {      $cards = 1;      echo '<table id="cards" class="cards">';      echo '<tr>';      foreach ($this->datacount $datacount) {          echo '<td>' . $head->machine_text . ' ' . $head->machine_name . ' [' . $datacount->count . ']</td>';      }      echo '</tr>';     echo '<tr>';     echo '<td>';     echo '<ul id="sortable" class="connectedsortable">';      foreach ($this->data $body) {          if ($head->machine_text == $body->machine_text) {              echo '<li class="ui-state-default">auftrag: ' . $body->aufnr;             echo '<br>' . $body->matnr . ' ' . $body->matxt;             echo '<br>menge ' . $body->gamng;             echo '<br><br>';             echo 'start: ' . $body->gstrp;             echo '<br>ende: ' . $body->ssavd . '</li>';              if ($cards++ == 10) {                 break;             }          } else {          }      }      echo '</td>';     echo '</tr>';     echo '</table>';  }  ?> 

the $cards defines amount of rows want display, want count rows aren't displayed aswell.

tl;dr create tables foreach, want count rows single table

above youre foreach loop, define counter.

$count = 0

then in foreach loop:

$count = $count + 1

after foreach loop:

echo $count

example:

<?php  foreach ($this->datatitle $head) {  $count = 0; $cards = 1;  echo '<table id="cards" class="cards">';  echo '<tr>';  foreach ($this->datacount $datacount) {     $count = $count + 1;     echo '<td>' . $head->machine_text . ' ' . $head->machine_name . ' [' . $datacount->count . ']</td>';  }  echo '</tr>'; echo '<tr>'; echo '<td>'; echo '<ul id="sortable" class="connectedsortable">';  foreach ($this->data $body) {      if ($head->machine_text == $body->machine_text) {          echo '<li class="ui-state-default">auftrag: ' . $body->aufnr;         echo '<br>' . $body->matnr . ' ' . $body->matxt;         echo '<br>menge ' . $body->gamng;         echo '<br><br>';         echo 'start: ' . $body->gstrp;         echo '<br>ende: ' . $body->ssavd . '</li>';          if ($cards++ == 10) {             break;         }      } else {      }  }  echo '</td>'; echo '</tr>'; echo '</table>'; echo $count; } ?> 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -