Jump to content

[SOLVED] php create new row


chriscloyd

Recommended Posts

i need help creating a new row for a table

say i have 8 teams i want three coloums made then when it shows three

make a new row

this is all i can think of

<?php
if ($pic_num == 1) { echo '<tr>'; }
if ($pic_num == 4) { echo '<tr>'; }
if ($pic_num == 7) { echo '<tr>'; }
if ($pic_num == 10) { echo '<tr>'; }
if ($pic_num == 13) { echo '<tr>'; }
?>

 

im just so lost on how to do this my meds are driving me crazy

 

 

Link to comment
https://forums.phpfreaks.com/topic/133611-solved-php-create-new-row/
Share on other sites

The modulus operator, %, gives you the remainder from dividing two numbers.  This can used to display something every x amount of iterations:

 

<?php
$data = array(1, 45, 12, 4, 58, 684, 51, 6, 8, 7, 21, 67);
$cols = 3;
$count = 0;
echo "<table><tr>";
foreach ($data as $datum) {
    if ($count != 0 && $count % $cols == 0) {
        echo "</tr><tr>";
    }
    echo "<td>$datum</td>";
    $count++;
}
echo "</tr></table>";
?>

Here it is, line by line:

 

1: Open PHP tag

2: Set up example data array

3: Specify number of columns per row we want

4: Initialize a count so we don't get nasty 'undefined variable' notices

5: Start table and first row

6: Begin foreach loop through data

7: Check to see if the remainder of $count / $cols is equal to 0.  If it is, it means that $count is divisible by $cols, so it's gone through $cols number of rows.

8: End old row, start new one

9: END IF $count % $cols == 0

10: Echo data in table cell

11: Increase count

12: END FOREACH $data as $datum

13: Finish off last row and close table

14: Close PHP tag

this is what i get hmmm

1 45 12

4 58 684

51 6 8

7 21 67

doesnt really work the right way hmmm

im doing it while getting info from database

$get_all_players = mysql_query("SELECT * FROM users WHERE team1 OR team2 OR team3 = 1 ");

then do a while statement so i can show each user

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.