Home > OS >  Add a limit to the html table
Add a limit to the html table

Time:03-29

I'm pulling data using php dom parser and writing it to the table but I don't want all of this data to come in I want to add a limit How can I do it

 <?php $st = 0;foreach ($c as $item): ?>                       
    <tr>
      <td> <?php echo $saat = $item->find("time",0)-> plaintext;  ?> </td>
      <td> <?php echo $takim1 = $item->find("span.homespan",0)-> plaintext;  ?> </td>
      <td><?php echo $takim2 = $item->find("span.awayspan",0)-> plaintext;  ?> </td>
      <td> <?php echo $oran = $item->find(".tipdiv > span",0)-> plaintext;  ?> </td>
    </tr>
 <?php endforeach ?>           

CodePudding user response:

If you mean you want to limit the number of items you're displaying, you can simply set a counter, and stop the loop when the count reaches that limit. For example:

<?php
$limit = 10;

for ($i = 0; $i < $limit; $i  )
{
  $item = $c[$i];
  ?>
  <tr>
    <td><?php echo $saat = $item->find("time",0)-> plaintext; ?></td>
    <td><?php echo $takim1 = $item->find("span.homespan",0)-> plaintext; ?></td>
    <td><?php echo $takim2 = $item->find("span.awayspan",0)-> plaintext; ?></td>
    <td><?php echo $oran = $item->find(".tipdiv > span",0)-> plaintext; ?></td>
  </tr>
  <?php
}
?>

CodePudding user response:

change your foreach with for loop

$limit = 20;
for($i=0; $i < $limit ; $i   ) {
//do some loop until limit reached
}
  • Related