table that gives even and odd numbers

0

I'm making a table with Boostrap and PHP to do odd and even numbers I'm doing it in for but I do not know why it does not print odd and even.

I do not know much of Boostrap with PHP .

With this for I generate it but it does not print me in pairs or odd

for($i=1; $i<10; $i++)
{
    echo "<tr>";
    echo "<td>".$i."</td>";
    echo "<td>".(11-$i)."</td>";
    echo "<td>".($i%2==0)."</td>";
    echo "<td>".($i%2 !=0)."</td>";
    echo "<td>".$i."</td>";
    echo "</tr>";

}
?>

I introduced

<!DOCTYPE html>
<html lang="en">
<head>
<title>Este ejercicio es del for</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
   <h2>Basic Table</h2>
   <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>            
   <table class="table">
     <thead>

        <th>1 a 10</th>
        <th>10 a 1</th>
        <th>  par </th>
        <th> impar </th>
        <th> 5 en 5 </th>
     </thead>
     <tbody>
       <?php

          for($i=1; $i<10; $i++)
          {
              echo "<tr>";
              echo "<td>".$i."</td>";
              echo "<td>".(11-$i)."</td>";
              echo "<td>".($i%2)."</td>";
              echo "<td>".($i%2 !=0)."</td>";
              echo "<td>".$i."</td>";
              echo "</tr>";

          }
       ?>





     </tbody>
   </table>
 </div>

</body>
</html>
    
asked by wdwd 23.03.2018 в 17:59
source

2 answers

0

You can try this code

    <!DOCTYPE html>
    <html lang="en" dir="ltr">
      <head>
        <meta charset="utf-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
      </head>
      <body>

          <table class="table">
    <thead>
      <tr>
        <th>1 a 10</th>
        <th>10 a 1</th>
        <th>  par </th>
        <th> impar </th>
        <th> 5 en 5 </th>
      </tr>
    </thead>
    <tbody>
    <?php
    for($i=1; $i<=10; $i++)
{
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td>".(11-$i)."</td>";
if($i%2 == 0){
echo "<td>".($i%2)."</td>";
}else{
echo "<td>No es par</td>";
}
if($i%2 == 0){
echo "<td>No es impar</td>";
}else{
echo "<td>".($i%2)."</td>";
}
echo "<td>".$i."</td>";
echo "</tr>";

}
     ?>
   </tbody>
 </table>
  </body>
</html>
    
answered by 23.03.2018 / 20:51
source
1

Look here you have a demo that prints on a table the numbers of 1 ... 10 and if the number is even or not. You can extend this code according to your needs.

<!DOCTYPE html>
<html>
<head>
    <title>DEMO PAR | IMPAR</title>
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body>

    <table class="table">
  <thead>
    <tr>
      <th scope="col">NUMERO:</th>
      <th scope="col">PAR / IMPAR</th>
    </tr>
  </thead>
  <tbody>

    <!-- Con esta sintaxis puedes utilizar elementos HTMl dentro de un for por ejemplo. -->
    <?php for($i=1;$i<=10;$i++): ?>
        <tr>
          <th scope="row"><?php echo $i; ?></th>
            <!-- Si el resto de la divicion da 0, significa que es par. -->
          <td><?php echo $i%2==0?"Si":"No"; ?></td>
        </tr>

    <?php endfor ?>

  </tbody>
</table>

</body>
</html>
    
answered by 23.03.2018 в 18:54