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
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>";
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.