Contact

If you like a new Web or Desktop
application, update a existing one
or add new modifications. Your at
the right place and hit the
hire me button

Follow

If your intersted you can follow
me on Twitter by clicking here

Web and Apps Building Refernce World Wild Web UNIX Apps AND Tips Programming languages

Build a drupal 6 table

How to build a drupal 6 table with out a DB

In this first example i will let you see how to build a simple DRUPAL 6 table with out a DB.


    function my_module_hook_table ()    
    {
        $header = array('header_item_1', 'header_item_2');

        $rows[] = array(
                    array('data' => $some_value_1, 'align' =>'center'),
                    array('data' => $some_value_2, 'valign' => 'top'),    
        );
       
        $rows[] = array(
                    array('data' => $some_value_1, 'align' =>'center'),
                    array('data' => $some_value_2, 'valign' => 'top'),        
        );
        
        $table_attributes = array('id' => 'my_id_for_table', 'align' => 'center');
        $output .= theme('table', $header, $rows, $table_attributes);
        
        return $output;
    }
     

 
How to build a drupal 6 table with a DB

In this second example i will let you see how to build a simple DRUPAL 6 table with a DB.

    function my_module_hook_table ()    
    {
        $header = array('header_item_1', 'header_item_2');

        $query = "SELECT * FORM {some_table} WHERE field = '%s'";
        $result = db_query($query, $some_value);
        while ($row = db_fetch_object($result))
        {
            $rows[] = array(
                        array('data' => $row->some_value_1, 'align' =>'center'),
                        array('data' => $row->some_value_2, 'valign' => 'top'),    
            );
        }
       
        $table_attributes = array('id' => 'my_id_for_table', 'align' => 'center');
        $output .= theme('table', $header, $rows, $table_attributes);
        
        return $output;
    }

How to build a drupal 6 table in a table and a db

In this first example i will let you see how to build a simple DRUPAL 6 table in a table.

    function my_module_hook_table ()    
    {
        $header = array('header_item_1', 'header_item_2');

        $query = "SELECT * FORM {some_table} WHERE field = '%s'";
        $result = db_query($query, $some_value);
        while ($row = db_fetch_object($result))
        {        
            $subquery = "SELECT * FROM {some other table} WHERE card_id = '%s' ";
            $subresult = db_query($subquery, $row->vcbfid);
            
            $subheader = array('sub header 1', 'sub header 2', 'sub header 3');
            $subrows = array();
            while ($subrow = db_fetch_object($subresult))
            {
                $subrows[] = array(
                                array('data' => $subrow->value_1, 'width' => '200'),
                                array('data' => '<p>some sub value</p>', 'width' => '200'),
                                array('data' => $subrow->vaule_2),
                );
            }
            
            $subtable_attributes = array('id' => 'sub_table_id', 'attribute' => 'value');
            $suboutput = theme('table', $subheader, $subrows, $subtable_attributes);
            $rows[] = array(
                        array('data' => $row->some_value_1, 'align' =>'center'),
                        array('data' => $suboutput, 'valign' => 'top'),    
            );
        }
       
        $table_attributes = array('id' => 'my_id_for_table', 'align' => 'center');
        $output .= theme('table', $header, $rows, $table_attributes);
        
        return $output;
    }