Computer problems,Computer help
*AX SOFT>>>Programming & Design

How do I display more than one column from a php while loop calling one field?


I want the information I retrieved with the while loop to be displayed in 3 columns and start a new row after the 3 columns.

In this example a table is used:

// here you can set the number of columns
$numOfCols = 3;

// this is a counter
$numOfEntries = 0;

echo "<table>";
while( ... ) {
// first check if a new row is starting
if ($numOfEntries % $numOfCols == 0){
// a new row is starting
echo "<tr>";
}

echo "<td>";
// print out your data
echo "</td>";

// at last check if this is the end of the row
if ($numOfEntries % $numOfCols == $numOfCols -1){
// close the row
echo "</tr>";
}
$numOfEntries ++;
}

// check if the last row is not closed
// $numOfEntris was inceremented(!)

if ($numOfEntris % $numOfCols != 0){
// it would be nice to print some empty cell here
// close the last row
echo "</tr>";
}

echo "</table>";

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • What are some great bit torrent sites?

    ck out {Kceasy} download it from the filesharing place.

    ...
  • Does Gimp 2.4.4 work on vista?

    yeah it will work. how much ram do you have? in the my computer thing it should tell you the ram. im only 15 years old but i know the technical field very well, for graphic designers you need...

  • Palindrome Words in Javascript?

    <html> <head> <!-- No matter which you select as "best answer" - pick one. --> <script> function get(eid) { var d = document; var r = d.getElementById(e...

  • I need to no a free website or program where i can edit photos? Like i want to make a photo into a puzl photo?

    The Gimp is a great image editing program! It's a lot like photoshop except $700 cheaper. It's a free program and you can download it straight from ...

  • How do you let users create there own web page in my page?

    the easiest way would be o use something like xoops: ...

  • What program can i use to create an animated GIF?

    UnFREEz 2.1 is a great program to use it very basic and easy to use but it gets strait to the point. ...

  • Web design and Graphic design?

    Ok. So My answer is a bit different from the other guys. I'm the director of training for an online creative training company (we train web design, graphic arts, marketing, Adobe Software etc)...

  • What is wrong with my c++ code?

    i'm a rookie, but are you sure there is supposed to be a ; (semicolen) ending line (b) ? isn't line (a) supposed to end in { for the statement on the next line? for(int y=0; y<Fi...

  •  

    Categories--Copyright/IP Policy--Contact Webmaster