表格加入HTML

时间:2016-03-03 20:00:09

标签: php mysql

这是我的索引...

  • 第1章(链接)
  • 第2章(链接)

当我点击索引中的第1章或第2章时,它会引导我进入same group of questions。问题组仅属于Chapter 1。如何将第1章问题放在第1章链接中,将第2章问题放在第2章链接中(当我最终添加一些时)。

这是我的第一组代码......

    <?php
    require_once 'init.php';

    $pollsQuery = $db->query("
        SELECT id, title
        FROM polls_chapters
    ");
    while ($row = $pollsQuery->fetchObject()) {
        $polls_chapters[] = $row;
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Index</title>
    <link rel="stylesheet" href="main.css">
</head>
<body>

    <?php if(!empty($polls_chapters)): ?>
        <ul>
            <?php foreach($polls_chapters as $poll_chapter): ?>
                <li>
                    <a href="questions.php?chapter=<?php echo $poll_chapter->id; ?>"><?php echo $poll_chapter->title; ?></a>
                </li>
            <?php endforeach; ?>
        </ul>
    <?php else: ?>
        <p>Sorry, nothing is available at the moment.</p>
    <?php endif; ?>

</body>
</html>

这是我的第二组代码......

<?php
    require_once 'init.php';

    $pollsQuery = $db->query("
        SELECT id, question
        FROM polls
        WHERE DATE(NOW()) BETWEEN starts AND ends
    ");
    while ($row = $pollsQuery->fetchObject()) {
        $polls[] = $row;
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Questions</title>
    <link rel="stylesheet" href="main.css">
</head>
<body>

    <?php if(!empty($polls)): ?>
        <ul>
            <?php foreach($polls as $poll): ?>
                <li>
                    <a href="poll.php?poll=<?php echo $poll->id; ?>"><?php echo $poll->question; ?></a>
                </li>
            <?php endforeach; ?>
        </ul>
    <?php else: ?>
        <p>Sorry, nothing is available at the moment.</p>
    <?php endif; ?>

</body>
</html> 

0 个答案:

没有答案