PHP Dynamic Table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Moggs-2005
Forum Newbie
Posts: 2
Joined: Thu Jan 28, 2010 7:15 am

PHP Dynamic Table

Post by Moggs-2005 »

Hi,
I want to build a dynamic table so it will go three columns wide then drop to a new row and so on but then if it gets to the end and there are only 2 columns to center them with the above rows
I am using CSV Files for my data.

Code: Select all

<?php
        $Name = $_GET['ProdCat'];
        $Type = $_GET['ProdType'];
        
                //echo('Insert produts for '.$Name.' catagory of type '.$Type);
        //
        // determine the page to display based on the type parameter
        //
        switch ($Type)
        {
                // image buttons in the displayed in the header of the opening page (HeaderFrame2.php)
            case "headerimagebutton":
                        //echo ('HIB');
                include $Name.'.php';
                break;
                
                // product catagories displayed on the openingpage (catagoryFrame.php)
            default:
                // insert dynamic build code here
                //echo ('we will build the products page for the catagory '.$Name.' here.');
                echo '<table align="center" width="90%" >';
                $i = 1;
                $HomeFolder=getcwd();
                $CatsFolder="Product Catagories/$Name";
                $CatsListFile="$Name.csv";
                $Caption="";
                $Name="";
                $Code="";
                $Image="";
                
                          
                $file=fopen($HomeFolder."/".$CatsFolder."/".$CatsListFile,"r") or exit("Unable to open file!");
                while(!feof($file))                 
                    {
                    $FileLine=fgets($file);
                    $Array=explode(",",$FileLine); 
                    $Caption=$Array[0];
                    $Name=$Array[1];
                    $Code=$Array[2];
                    $Image=$Array[3];
                    
                    echo '<table width="90%">';
                            echo '<td align="center">';
                                echo '<table border="1">';
                                    echo '<tr align="center">';
                                        echo '<td>';
                                            echo $Caption;
                                        echo'</td>';
                                    echo'</tr>';
                                echo'</table>';
                            echo'<br>';             
                        echo'</td>';
                                
    if($i==3)
            {
                print "<table width='90%' align='center'>";
            $i = 1;
            }
                        else 
                            {
                                $i++;
                            }
    }
    
    echo '</table>';
            
                fclose($file);
                    
                break;
        }
    ?>
Please Help i have been stuck on this problem for a while now

The Code in there at the moment worked when it wasnt in a switch case? Would this have anything to do with in??
Cheers Jack
Moggs-2005
Forum Newbie
Posts: 2
Joined: Thu Jan 28, 2010 7:15 am

Re: PHP Dynamic Table

Post by Moggs-2005 »

I am still having problems with this code?? Any help would be greatly appreciated.
Jack M
Post Reply