从数据库中提取页面的问题

时间:2018-11-17 13:45:38

标签: php html5 mysqli

我在用过的PHP和HTML中浏览页面时遇到了问题:-

    <li>
     <!-- Pulling Categories from the database 
     dynamically -->
<?php 
    $nav_subjects = find_all_subjects(['visible' => $visible]);

    while($nav_subject = 
        mysqli_fetch_assoc($nav_subjects)) { 
?>
    <span class="opener"><?php echo h($nav_subject['menu_name']); ?></span>

从数据库中动态提取类别,并使用下拉箭头显示类别,这正是我想要的,但是页面不会显示在它们的下面,这是我使用的代码:-

<!-- Categories listed correctly let's pull the pages for each one -->
<?php 
    if($nav_subject['id'] == $subject_id) {
        $nav_pages = find_pages_by_subject_id($nav_subject['id'], ['visible' => $visible]); 
        while($nav_page = mysqli_fetch_assoc($nav_pages)) { 
?>
    <ul>
    <li>
    <a href="<?php echo url_for('index.php?id=' . h(u($nav_page['id']))); ?>"><?php echo h($nav_page['menu_name']); ?></a>
    </li>
    </ul>
<?php   } // while $nav_pages 
    } // if($nav_subject['id'] == $subject_id) 
  } // while $nav_subjects ?>
    </li>
<?php 
    mysqli_free_result($nav_subjects);
    mysqli_free_result($nav_pages); 
?>

我正在从另一个页面中提取SQL,该页面在类别加载并正确显示时会正确加载。

任何想法我都会感激的。

我也试图回显sql结果,但未显示任何内容。

我现在可以通过以下代码使用它:-

                                        <li>

                                        <?php $nav_subjects = find_all_subjects(['visible' => $visible]);
                                             while($nav_subject = mysqli_fetch_assoc($nav_subjects)) {?>
                                                 <span class="opener"><?php echo h($nav_subject['menu_name']); ?></span>
                                        <ul>
                                        <?php if($nav_subject['id'] == $subject_id);
                                        $nav_pages = find_pages_by_subject_id($nav_subject['id'], ['visible' => $visible]);
                                         while($nav_page = mysqli_fetch_assoc($nav_pages)) { ?>
                                            <li><a href="<?php echo url_for('index.php?id=' . h(u($nav_page['id']))); ?>"><?php echo h($nav_page['menu_name']); ?></a></li>


                                    <?php } ?>
                                <?php } ?>
                                        </ul>

但是现在它将次要科目列为第一个科目的孩子,而不是他们自己的单个科目。

*********已解决**********

请告知您您是否认为我目前使用的代码更好:-

                                        <li>
                                        <?php $nav_subjects = find_all_subjects(['visible' => $visible]);?>
                                        <?php while($nav_subject = mysqli_fetch_assoc($nav_subjects)){?>
                                             <span class="opener"><?php echo h($nav_subject['menu_name']);?></span>
                                        <ul>
                                        <?php if($nav_subject['id'] == $subject_id);
                                        $nav_pages = find_pages_by_subject_id($nav_subject['id'], ['visible' => $visible]);
                                         while($nav_page = mysqli_fetch_assoc($nav_pages)) { ?>
                                         <a href="<?php echo url_for('index.php?id=' . h(u($nav_page['id']))); ?>">
                                                <?php echo h($nav_page['menu_name']); ?></a>
                                            <?php } ?>
                                                <?php mysqli_free_result($nav_pages); ?>
                                        </ul>
                                        <?php } ?>
                                            <?php mysqli_free_result($nav_subjects); ?>
                                    </li>

0 个答案:

没有答案