Note that there are some explanatory texts on larger screens.

plurals
  1. POiterate a html table of two row and 3 column using one php query
    primarykey
    data
    text
    <p>I have a database table and that table has 6 rows. What I want is to display that 6 rows in a html page using a 3 column and 2 row table.</p> <p>I know how to work with php arrays and while loops. My problem is how to limit the array to put 3 items in the first row and put the other 3 in the next row. </p> <p>this is what i have tried but didn't work </p> <pre><code>&lt;div id="maincontent"&gt; &lt;!-- class one --&gt; &lt;?php $getSection = getSection(); $i=0; while($allSection = mysql_fetch_array($getSection)){ ?&gt; &lt;div class="subconent"&gt; &lt;table width="937" border="0"&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="sub_image"&gt; &lt;a href="section.php?id=&lt;?php echo urlencode($allSection['id']); ?&gt;"&gt;&lt;img src="admin/uploads/fron_sect/&lt;?php echo $allSection['image']; ?&gt;" width="134" height="120" border="0" alt="HNA" class="PopBoxImageLink" onmouseover="PopEx(this,-50,-25,205,186,20,null);" onclick="window.location='http://localhost/hants/section.php?id=&lt;?php echo urlencode($allSection['id']); ?&gt;'" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;div class="cont_txt"&gt; &lt;h3&gt;&lt;?php echo $allSection['name_full']; ?&gt;&lt;/h3&gt; &lt;p&gt;&lt;?php echo substr($allSection['description'],0,140) . ""; ?&gt;&lt;/p&gt; &lt;br /&gt; &lt;a href="section.php?id=&lt;?php echo urlencode($allSection['id']); $i++; ?&gt;"&gt;&lt;img src="images/read_more.jpg" alt="Read More" width="89" height="25" border="0" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;?php if($i==4) { ?&gt; &lt;table width="937" border="0"&gt; &lt;tr&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;div class="sub_image"&gt; &lt;a href="section.php?id=&lt;?php echo urlencode($allSection['id']); ?&gt;"&gt;&lt;img src="admin/uploads/fron_sect/&lt;?php echo $allSection['image']; ?&gt;" width="134" height="120" border="0" alt="HNA" class="PopBoxImageLink" onmouseover="PopEx(this,-50,-25,205,186,20,null);" onclick="window.location='http://localhost/hants/section.php?id=&lt;?php echo urlencode($allSection['id']); ?&gt;'" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;div class="cont_txt"&gt; &lt;h3&gt;&lt;?php echo $allSection['name_full']; ?&gt;&lt;/h3&gt; &lt;p&gt;&lt;?php echo substr($allSection['description'],0,140) . ""; ?&gt;&lt;/p&gt; &lt;br /&gt; &lt;a href="section.php?id=&lt;?php echo urlencode($allSection['id']); ?&gt;"&gt;&lt;img src="images/read_more.jpg" alt="Read More" width="89" height="25" border="0" /&gt;&lt;/a&gt; &lt;/div&gt;&lt;td&gt; &lt;?php } } ?&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload