tables and while loops

Can I ask a question? Please
I am trying to repeat tables in PHP with a while loop. I am just not getting it. I have a table with Div statement in it. If I want it to repeat 5 times can someone please suggest how I would do that? Please.

This is really easy to do, post what you have and one of us will tweak it for you.

while loop
[php]$i = 0;
while ($i < 5) {
echo ‘

Some content
’;
$i++;
}[/php]

for loop
[php]for ($i = 0; $i < 5; $i++) {
echo ‘

Some content
’;
}[/php]

To read:
http://php.net/manual/en/control-structures.foreach.php
http://php.net/manual/en/control-structures.for.php
http://php.net/manual/en/control-structures.while.php
http://php.net/manual/en/control-structures.do.while.php

I fixed that but I am really not understanding where I put the loop at. Does it go after the opening body? I am also not understanding how to make the loop put up 5 different boxes. Do I have to put all the

code in the while loop? Thank You For Taking The Time To Look At This.

Can you post what you have done so far and show us what you want it to look like?

You should put the loop where you want the data to show. In the loop you must include all the code you wish to be repeated.

Full example using bootstrap
[php]<?php
ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);

$names = array(
‘JimL’,
‘topcoder’,
‘plat’
);

?>

Test site
<div class="navbar navbar-inverse navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Project name</a>
    </div>
    <div class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</div>

<div class="container">

  <div class="starter-template">
    <h1>Test</h1>
    <ul>
       <?php foreach ($names as $name) { ?>
       <li><?= $name ?></li>
       <?php } ?>
    </ul>
  </div>

</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://codeorigin.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/default.js"></script>
[/php]

This will output:

[php]

Test site
<div class="navbar navbar-inverse navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Project name</a>
    </div>
    <div class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</div>

<div class="container">

  <div class="starter-template">
    <h1>Test</h1>
    <ul>
                  <li>JimL</li>
                  <li>topcoder</li>
                  <li>plat</li>
               </ul>
  </div>

</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://codeorigin.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/default.js"></script>
[/php]

the most interesting part beeing this:
[php]


  • JimL

  • topcoder

  • plat

[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service