Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2012
    Posts
    89
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Issue with displaying results using $count

    Hello,

    I have a dynamic page to show signups for each event. What I want to do is, when there are 5 or less people signed up, to display one table like so:

    PHP Code:
    <table>
    <
    tr>
    <
    td>Signup #1</td>
    <td>Signup #2</td>
    <td>Signup #3</td>
    </tr>
    </
    table
    ... And so on. Once I have 6 OR 7 signups, I want to show it like this:

    PHP Code:
    <table>
    <
    tr>
    <
    td>Signup #1</td>
    <td>Signup #2</td>
    <td>Signup #3</td>
    <td>Signup #4</td>
    <td>Signup #5</td>
    </tr>
    <
    tr>
    <
    td>Signup #6</td>
    <td>Signup #7</td>
    </tr>
    </
    table
    ... So once the $count is more than 5, it should add ONE more <tr> and show the 6thth AND/OR 7th signup there. What I have right now is this:

    PHP Code:
    <?php
    $count 
    "0";

    while(
    $row mysql_fetch_array($result)){

    // some stuff here
    ?>

    <tr>
    <td><?php echo "$name"?></td>
    </tr>

    <?php
    $count
    ++;
    if(
    $count == "5" || $count == "6")

    ?>

    </tr>
    <tr> Reserves</tr>

    <?php
    }
    }
    ?>
    But what this does is, it shows the </tr><tr> TWICE, so it becomes like this:

    PHP Code:
    <table>
    <
    tr>
    <
    td>Signup #1</td>
    <td>Signup #2</td>
    <td>Signup #3</td>
    <td>Signup #4</td>
    <td>Signup #5</td>
    </tr>
    <
    tr>
    <
    td>Signup #6</td>
    </tr>
    <
    tr>
    <
    td>Signup #7</td>
    </tr>
    </
    table
    Any ideas?

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    723
    Thanks
    20
    Thanked 84 Times in 84 Posts
    your telling it to:

    PHP Code:
    <?php
    $count
    ++;
    if(
    $count == "5" || $count == "6")

    ?>
    remove if 6

    PHP Code:
    <?php
    $count
    ++;
    if(
    $count == "5")

    ?>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    723
    Thanks
    20
    Thanked 84 Times in 84 Posts
    also if you want it so that EVERY 5 items creates a new row reset count also

    PHP Code:

     <?php
    $count 
    "0";

    while(
    $row mysql_fetch_array($result)){

    echo 
    "
    <tr>
    <td>$name</td>
    </tr>"
    ;

    $count++;
    if(
    $count == "5"){ 

    echo 
    "
    </tr>
    <tr> Reserves</tr>
    "
    $count "0"
    }
    }
    ?>



    EDIT: nvm i just realised its a 5 a side football team
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #4
    Junsee
    Guest
    I normally use modulus in this case

    PHP Code:
    <?php 
    $count 
    1
    echo 
    '<tr>';
    while(
    $row mysql_fetch_array($result)){ 

        echo 
    '<td>' .$name'</td>';
        if( 
    $count%== "0" ) {  
            echo 
    '</tr>';
            echo 
    '<tr>';
        }
        
    $count++; 
    }
    echo 
    '</tr>';
    ?>
    modulus says when the $count is divisable by 5, and equals 0 (no remainder, a whole number) then do this code, which is insert a new line on the table.
    Last edited by Junsee; 04-08-2013 at 11:23 PM. Reason: add code

  • Users who have thanked Junsee for this post:

    Hardist (04-09-2013)

  • #5
    New Coder
    Join Date
    Apr 2012
    Posts
    89
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Thanks for the help, got it working now


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •