douqiandai4327 2013-03-30 18:03
浏览 41
已采纳

使用PHP自动更新引导程序布局

I'm trying to generate a layout with php and jQuery which lists certain profiles and organizes them in a certain way.

Specifically, I have an array of program titles and I'd like to list all of the program titles on the page as headers with two program titles per row. Then, I have an array of names which each contain an array of program names. I'd like to list all of the users that have a certain program in their array underneath the relevant program title. Additionally, the names start off hidden and each program title has a button underneath it which hides and shows tutors. I've created this layout using Bootstrap here:

        <?php
        include ('objects.php');

        function tutorCreator($tutorName, $boxNum, $spanClass){
            include ('objects.php');
            echo "<div class='" . $spanClass . " tutorBox" . $boxNum . "'>";
            }
    ?>
        <div class="row-fluid">
            <span class="programHeader span5">DreamWeaver</span>
            <span class="programHeader offset1 span5">GIMP</span>
        </div>
        <div class="row-fluid">
            <span class="span2 showTutors">Show tutors</span>
            <span class="span2 offset4 showTutors">Show tutors</span>
        </div>
            <div class="row-fluid">
                <?php 
                    tutorCreator('Kevin Marks', '1', "span4");
                    tutorCreator('Kevin Marks','2', "span4 offset2");
                ?>
            </div>
            <div class="row-fluid">
                <?php 
                    tutorCreator('Helen Larson', "1", "span4");
                    tutorCreator('Helen Larson','2', "span4 offset2");
                ?>
            </div>
        <div class="row-fluid">
            <span class="programHeader span5">Google Analytics</span>
            <span class="programHeader offset1 span5">HootSuite</span>
        </div>
        <div class="row-fluid">
            <span class="span2 showTutors">Show tutors</span>
            <span class="span2 offset4 showTutors">Show tutors</span>
        </div>
            <div class="row-fluid">
                <?php 
                    tutorCreator('Ken Gato', '3', "span4");
                    tutorCreator('Julien Mans', '4', "span4 offset2");
                ?>
            </div>
            <div class="row-fluid">
                <?php 
                    tutorCreator('Ommed Kosh', '3', "span4");
                ?>
            </div>

The classes added to the tutor names are for the purpose of being shown when the appropriate "show tutors" button is listed and to help with the layout.

The objects.php file contains the arrays with the list of tutors and the list of programs. This layout works fine. However, I'm trying to change the php code so that this layout is automatically updated each time I add a program or a tutor to the arrays in objects.php. I've been trying to figure it out for a few days and I just can't get an automatically updated layout which works well. I realize this is probably too broad a question but I've hit a road block so any help would really be appreciated. You can see a fuller version of the current layout here: http://www.tutorgrams.com/tutors. Thanks for any help.

Here is the objects.php file (with some tutors and programs removed for brevity):

<?php

$programs = array();

$programs['DreamWeaver'] = array(
'name' => 'DreamWeaver');

$programs['GIMP'] = array(
'name' => 'GIMP');

$programs['Google Analytics'] = array(
'name' => 'Google Analytics');

$programs['HootSuite'] = array(
'name' => 'HootSuite');


$tutors['Helen Larson'] = array(
'name' => 'Helen Larson',
'programs' => array('DreamWeaver', 'GIMP')
);

$tutors['Kevin Marks'] = array(
    'name' => 'Kevin Marks',
'programs' => array('DreamWeaver', 'GIMP')
);

$tutors['Ommed Kosh'] = array(
'name' => 'Ommed Kosh',
'programs' => array('Google Analytics')
);

$tutors['Julien Mans'] = array(
'name' => 'Julien Mans',
'programs' => array('HootSuite')
);

$tutors['Ken Gato'] = array(
'name' => 'Ken Gato',
'programs' => array('Google Analytics')
);

?>
  • 写回答

1条回答 默认 最新

  • doubu1970 2013-03-30 20:17
    关注

    How does this look?

    <?php 
    $numProgs = count($programs);
    $progs = array_keys($programs);
    
    $i = 0; ?>
    
    <?php while($i < $numProgs): ?>
    
        <div class="row-fluid">
            <span class="programHeader span5"><?php echo $progs[$i]; ?></span>
            <span class="programHeader offset1 span5"><?php echo $progs[$i + 1]; ?></span>
        </div>
        <div class="row-fluid">
            <span class="span2 showTutors">Show tutors</span>
            <span class="span2 offset4 showTutors">Show tutors</span>
        </div>
    
        <div class="row-fluid">
        <?php foreach($tutors as $name => $data) {
            $tutProgs = $data['programs'];
            if(in_array($progs[$i], $tutProgs)) {
                tutorCreator($name, $i, "span4");
            }
        } ?>
        </div>
    
        <div class="row-fluid">
        <?php
            foreach($tutors as $name => $data) {
                $tutProgs = $data['programs'];
                if(in_array($progs[$i + 1], $tutProgs)) {
                    tutorCreator($name, $i + 1, "span4 offset2"); 
                }
            }
        ?>
        </div>
    
        <?php $i += 2; ?>
    <?php endwhile; ?>
    

    It could probably be optimised a little but it seems to do the trick for me. The only thing is I don't have your themes so It might not look right yet.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作