Announcement

Collapse
No announcement yet.

Automatically number and colour table rows

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Automatically number and colour table rows

    Here's a bit of code to automatically number rows in a table and also colour the back ground of each row
    Code:
    <?php $count=1;?>
    <table>
    
    <!-- add the three following lines to the start of each new row-->
    <tr style='background-color:<?php echo ($count%2==0)?"#afa":"aaf"; ?>'>
      <td><?php  echo $count++;?></td>
    
    <!-- add the date-->
      <td >Data</td>
      <td>Data</td>
    </tr>
    
    ...
    </table>

    Of course it's much easier if your data is in an array because the table can be created using a loop.
    Last edited by black-dog; 02-02-09, 04:36 PM.
    black-dog
    4theweb.co.uk Web stuff
    slipperyhill.co.uk Band

  • #2
    Well, as you can see, or not see, my code example does not work. There seem to be a few problems with the forum...
    black-dog
    4theweb.co.uk Web stuff
    slipperyhill.co.uk Band

    Comment


    • #3
      OK, let's try again for the support people.

      Code:
      <?php $count=1;?>
      <table>
      
      <tr style='background-color:<?php echo ($count%2==0)?"#afa":"aaf"; ?>'>
        <td><?php  echo $count++;?></td>
        <td >Data</td>
        <td>Data</td>
      </tr>
      
      <tr>
        <td><?php  echo $count++;?></td>
        <td>Data</td>
        <td>Data</td>
      </tr>
      
      </table>
      black-dog
      4theweb.co.uk Web stuff
      slipperyhill.co.uk Band

      Comment


      • #4
        I will advice you to replace < , > and " symbols of your code with following :

        < = & lt;
        > = & gt;
        " = & quot;
        This update would display your code properly.

        You can use Find and Replace tool in Notepad and you have your tag ready
        UK VPS Hosting || Managed Server Hosting || Reseller Hosting
        Webhosting affiliate program can make you earn upto 100 Webhosting UK Affiliate

        Comment


        • #5
          Originally posted by harry View Post
          I will advice you to replace < , > and " symbols of your code with following :

          < = & lt;
          > = & gt;
          " = & quot;
          This update would display your code properly.

          You can use Find and Replace tool in Notepad and you have your tag ready
          Yes I know I could do that but surely the bbcode tags should do this?

          Here is the code using html entities

          &lt;?php $count=1;?&gt;
          &lt;table&gt;

          &lt;tr style='background-color:&lt;?php echo ($count%2==0)?&quot;#afa&quot;:&quot;aaf&quot;; ?&gt;'&gt;
          &lt;td&gt;&lt;?php echo $count++;?&gt;&lt;/td&gt;
          &lt;td &gt;Data&lt;/td&gt;
          &lt;td&gt;Data&lt;/td&gt;
          &lt;/tr&gt;

          ...
          &lt;/table&gt;
          black-dog
          4theweb.co.uk Web stuff
          slipperyhill.co.uk Band

          Comment


          • #6
            [php]
            <?
            php $count=1;
            ?>
            <table>

            <tr style='background-color:<?php echo ($count%2==0)?"#afa":"aaf"; ?>'>
            <td><?php echo $count++;?></td>
            <td >Data</td>
            <td>Data</td>
            </tr>

            <tr>
            <td><?php echo $count++;?></td>
            <td>Data - test by support Team</td>
            <td>Data - test by support Team</td>
            </tr>

            </table>
            [/php]

            Comment

            Working...
            X