Note that there are some explanatory texts on larger screens.

plurals
  1. POecho an array from mysql and in a table with defined rows and cols
    text
    copied!<p>I have got an array from mysql, now I am trying to put it into a table with 4 columns using a while loop. My method is that when <code>$counter%4==0</code>, I echo <code>&lt;/tr&gt;</code> so that every 4 items will be arranged in one row. But I can't get the result I want, so can anyone tell me where the problem is or offer me a better way to do this? Here is my code:</p> <pre><code>&lt;table border="0" cellspacing="0" cellpadding="0"&gt; &lt;tbody&gt; &lt;?php $query1 = "SELECT * FROM post WHERE post_status='New' AND post_type='Facilities' AND post_keywords='icon'"; $run1 = mysql_query($query1); $counter=0; while($row1 = mysql_fetch_array($run1)){ $post_id = $row1['post_id']; $post_title = $row1['post_title']; $post_date = $row1['post_date']; $post_author = $row1['post_author']; $post_keywords = $row1['post_keywords']; $post_type =$row1['post_type']; $post_content = $row1['post_content']; $post_status =$row1['post_status']; if($counter%4==0){ echo '&lt;tr&gt;'; } ?&gt; &lt;td&gt;//here is the content from the array &lt;div id="&lt;?php echo $post_id?&gt;" class="FacItem" onmousedown="function onmousedown() { fac_change('down','&lt;?php echo $post_id?&gt;') }" onmouseup="function onmouseup() { fac_change('up','&lt;?php echo $post_id?&gt;') }" onmouseover="function onmouseover() { fac_change('over','&lt;?php echo $post_id?&gt;') }" onmouseout="function onmouseout() { fac_change('out','&lt;?php echo $post_id?&gt;') }"&gt;&lt;a href="?page_id=282"&gt;&lt;?php echo $post_content?&gt;&lt;/a&gt;&lt;/div&gt; &lt;/td&gt; &lt;?php if($counter%4==0){ echo '&lt;/tr&gt;'; } $counter++; } ?&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre>
 

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