Easy way to creates XHTML valid tables

Discussion in 'PHP' started by astkboy2008, Dec 14, 2009.

  1. #1
    our method is depending on the PHP XHTML table class
    This class for PHP 5 easily creates XHTML valid tables with a simple and easy to remember syntax.
    Example


    $table = new table('border="1"');
    $table->caption('People');
    
    $table->part('head');
    $table->headers('Name',array('Age'=>'title="in years"'),'Country');
    
    $table->part('body','style="color:Blue;"');
    
    $table->row('');
    $table->cells('John',23,'USA');
    
    $table->row('');
    $table->cell('Jack');
    $table->cell('42');
    $table->cell('Mexico');
    
    $table->row('');
    $table->cell('Philip J. Fry');
    $table->cell('23');
    $table->cell('India');
    
    $table->part('foot','style="color:Violet;"');
    $table->cell("Total :");
    $table->cell(23+42+23);
    # empty cell
    $table->cell();
    
    # reopen a closed part, and add a row
    # won't increment the total, it's only an example
    $table->part('body');
    $table->row('style="color:Green;"');
    $table->cells('Igor',43,'Russia');
    
    echo($table);
    PHP:
    XHTML Output

    <table border="1">
    <caption>People</caption>
    
    <thead>
    <tr><th>Name</th>
    <th title="in years">Age</th>
    <th>Country</th>
    </tr>
    </thead>
    
    <tfoot style="color:Violet;">
    <tr><td>Total :</td>
    <td>88</td>
    <td> </td>
    
    </tr>
    </tfoot>
    
    <tbody style="color:Blue;">
    <tr><td>John</td>
    <td>23</td>
    <td>USA</td>
    </tr>
    
    <tr><td>Jack</td>
    <td>42</td>
    <td>Mexico</td>
    
    </tr>
    
    <tr><td>Philip J. Fry</td>
    <td>23</td>
    <td>India</td>
    </tr>
    
    <tr style="color:Green;"><td>Igor</td>
    <td>43</td>
    <td>Russia</td>
    </tr>
    
    </tbody>
    
    </table>
    Code (markup):
    Download

    php-xhtml-table20091206.zip [2.91 KB]
    http://www.jooria.com/downloads/441/php-xhtml-table20091206.zip
    Code (markup):
    or
    class.table.php [7.82 KB]
    http://www.jooria.com/view/file/441/0
    Code (markup):

     
    astkboy2008, Dec 14, 2009 IP
  2. taminder

    taminder Peon

    Messages:
    581
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ah.. thanks.
     
    taminder, Dec 15, 2009 IP
  3. Wogan

    Wogan Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #3
    Wouldn't it be easier to do:

    $row = array("Jack", "Harkness", "42");
    $table->addrow($row)
    PHP:
    ? Because then you can do:

    $result = mysql_query("SELECT * FROM `employees` ORDER BY `employeeid` ASC");
    while($row = mysql_fetch_assoc($result))
    {
    $table->addrow($row);
    }
    PHP:
    Just saying.
     
    Wogan, Dec 16, 2009 IP
  4. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thank you its really helpfull
     
    astkboy2008, Dec 16, 2009 IP
  5. ghprod

    ghprod Active Member

    Messages:
    1,010
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    78
    #5
    Like codeigniter table helper does :D

    regards ...
     
    ghprod, Dec 19, 2009 IP
  6. Wogan

    Wogan Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #6
    My point exactly. All this stuff already exists...
     
    Wogan, Dec 19, 2009 IP
  7. RevoBulletin

    RevoBulletin Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I do this for some of the scripts that I have. I really like it, since it cleans up main coding, at least I think it does.
     
    RevoBulletin, Dec 21, 2009 IP
  8. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    yes its good for big projects
     
    astkboy2008, Dec 22, 2009 IP