基于MySQL表的动态网格构建

时间:2015-03-12 12:06:37

标签: php mysql

所以我有一些代码提取表头,然后是列数据,因为我不知道头是什么。它工作得很好,但我不能让表格布局停止破坏目前我的所有数据都在第一列而不是在正确的标题下。有什么想法吗?

<table>
                <tr>
                    <?php       
                            $colnames = json_decode($colnames); 
                            foreach($colnames as $header) {                                                         
                            ?>
                                <th><?php echo $header->Field ?></th>
                            <?php
                            }                       
                    ?>
                    <th>
                        Options
                    </th>
                </tr>

                <?php       

                        $none = true;                       

                        foreach($colnames as $header) {   

                            echo "<tr>";

                            $field = $header->Field;
                            foreach($colojects as $object) {

                                    $none = false;                          
                                    echo "<td>".$object->$field."</td>";

                            }

                            echo "<td> [ Edit ] [ Delete ]</td>";

                            echo "<tr>";
                        }   


                ?>              

                <?php
                    if ($none){
                        echo "<tr><td>You currently have no data for this databin ".$_GET['DatabinName']."</td></tr>";  
                    }
                ?>
            </table>

1 个答案:

答案 0 :(得分:0)

似乎我只需要替换搜索foreach。

下面的解决方案
<?php       

                        $none = true;   

                        foreach($colojects as $object) {

                            $none = false;  

                            echo "<tr>";

                                foreach($colnames as $header) { 

                                    $field = $header->Field;


                                    echo "<td>".$object->$field."</td>";

                                }

                            echo "<td> [ Edit ] [ Delete ]</td>";

                            echo "</tr>";
                        }   


                ?>