试图将链接插入MySql循环

时间:2017-05-15 18:39:08

标签: php html mysql loops href

<ul class="items">
    <li>
        <span class = "item">
        <?php
        while ($row=mysqli_fetch_assoc($result))
        {
            foreach ($row as $key=>$val)
            {
                echo "{$val} " . " <br/>";
                echo "<br /><hr /><br />";
            }
        }
        mysqli_free_result($result); ?>
        <a href="#" class="done-button">Mark as done</a>
        </span>
    </li>
</ul>

我试图将其添加到循环中:

href="#" class="done-button">Mark as done

aka - 用于待办事项列表的Mark as Done按钮,以便它出现在每个输出的值旁边。但是,我只能在页面底部找到它。

1 个答案:

答案 0 :(得分:0)

你关闭了!你需要做的就是移动循环内部的链接,就像这样(我不确定你想要按钮的确切位置):

<ul class="items">
    <li>
        <span class = "item">
        <?php
        while ($row=mysqli_fetch_assoc($result))
        {
            foreach ($row as $key=>$val)
            {
                echo "{$val} " . " <br/>";
                echo "<br /><hr /><br />";
            }
            echo '<a href="#" class="done-button">Mark as done</a>';
        }
        mysqli_free_result($result); ?>
        </span>
    </li>
</ul>