Juje007 » Blog


PHP: Table Class

Uncategorized • October 1, 2010 • By Juje007 @ 8:49 pm • • 0 Comments


After some playing with PHP, I wanted to create a new class but I didn’t really know what. So after some time I founded a nice task to do :) . So here is my “Table Class”. It’s a easy way to create a HTML table from a PHP array.

The code:


<?php

class Table {
    function __construct() {
        $this->output = "<table>\r";
    }

    function addSingleRow($arr) {
        if(is_array($arr)){
            $output = "\t<tr>\r";
            foreach($arr as $item) {
                $output .= "\t\t<td>" . $item . "</td>\r";
            }
            $this->output .= $output . "\t</tr>\r";
        } else {
            $this->output .= "\t<tr>\r\t\t<td>" . $arr . "</td>\r\t</tr>\r";
        }
    }

    function addMultiRow($arr) {
        foreach($arr as $item) {
        if(is_array($item)){
            $output = "\t<tr>\r";
            foreach($item as $sItem) {
                $output .= "\t\t<td>" . $sItem . "</td>\r";
            }
            $this->output .= $output . "\t</tr>\r";
        } else {
            $this->output .= "\t<tr>\r\t\t<td>" . $item . "</td>\r\t</tr>\r";
        }
        }
    }

    function render() {
        echo $this->output . "</table>";
    }
}

?>

Usage:


<?php

require("Table.class.php"); // Get the class (the name may be different)

$table = new Table; // Load the Table Class

$table->addSingleRow("1 row"); // Adds 1 row and column
$table->addSingleRow(Array("First column", "Second column"); // Adds 1 row and 2 columns

$table->addMultiRow(Array("First row", "Second row")); // Adds 2 rows with 1 column
$table->addMultiRow(Array(Array("First row and column", "second column"), Array(Array("Second row and first column", "second column"); // Adds 2 rows and 2 columns

echo $table->render(); // Output everything

?>

This is a very simple Table Class because you can’t define attributes like title, class, id, etc. But you are free to use and to change off course :) .

Tags:

HTML5 and JavaScript

Uncategorized • July 2, 2010 • By Juje007 @ 1:31 pm • • 3 Comments


After reading a post about canvas at http://carsonified.com/blog/dev/html-5-dev/how-to-draw-with-html-5-canvas/ I wanted to create something with it. So I came up the idea to create a RGB color selector without the selecting part, because that will be to much work :( . But here is the result:

jsAndHtml5 RGB Selector

If you want to see the live version you can go to: http://www.juje007.be/canvas.html (you may download and use the source :) )

~Juje007

Tags:

WordPress 3.0

Uncategorized • June 18, 2010 • By Juje007 @ 8:54 am • • 0 Comments


Today WordPress 3.0 released so I installed it immediately and it looks quite good at the Admin Control Panel offcourse at the outside you will probably see no difference at all. But if you want to learn all about WordPress 3.0 go than to: http://wordpress.org/development/2010/06/thelonious/.

Tags:

New design and remake

Uncategorized • May 4, 2010 • By Juje007 @ 5:45 pm • • 0 Comments


Hey everyone,

It’s a long time ago now that I installed WordPress with a nice theme named Core. But my site was only about the blog and since I’m not really a blog writer I brought back the whole site with a complete remake so enjoy and come back as many times that you want.

Tags:

Ya LinkFast got his domain

Uncategorized • February 3, 2010 • By Juje007 @ 7:49 pm • • 0 Comments


After a long time that LinkFast was in beta status I finally bought a domain named LinkFast.be so now I can finally release it. So feel free to use it, at the moment it’s only in Dutch but the English version will come out soon.

Tags:

Recent Posts

Archives

Tags