Jump to content

Need help with loop rows and columns


forcom

Recommended Posts

I have 50 states and I want my loop display 5 columns.

 

right now my loop displays all 50 states in one column. I setup a table but I don`t know how to echo </td></tr><tr><td> every ten states in the loop.

 

I am trying to get it to do

 

1                                                continue

2                                                7

3                                                8

4                                                9

5                                                etc.

6 break echo </td></tr><tr><td>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/161209-need-help-with-loop-rows-and-columns/
Share on other sites

Can you post the relevant code?  You said you want to display every 10 rows, yet your example does not exemplify this.

 

You have to use the modulus (%) operator in your while loop to check if the row count is divisible by 10 (every 10 rows).

 

 

NOTE - Is there a reason you posted in the Framworks section?  If not, I can move this to the more popular, "PHP Help" for additional help.

Sorry about the example it would have been too much typing.  You can move it to help.

 

$ctryfrom = "SELECT DISTINCT country FROM table";
$ctry = mysql_query($ctryfrom);

while($row = mysql_fetch_assoc($ctry)){
$countrynames = $row['country'];

echo '<table><tr><td>';
echo "$countrynames";

//I want to echo </td></tr><tr><td> to add another column in the table. How can I set it to echo
            }


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.