【发布时间】:2016-10-03 17:10:08
【问题描述】:
我的问题是:我想使用 php 从<select> 中的特定表中显示所有 SQL 答案。
我试图让它工作,但没有多大成功,因为它只显示一个结果。
<?php
error_reporting(E_ALL);
include 'connect.php';
include 'header.php';
set_time_limit(10);
$cat = $bdd->query('SELECT cat_id,cat_name,cat_description FROM categories');
$categories_list = $cat->fetch();
While ($categories_list = $cat->fetch()) {
$cat_name = $categories_list['cat_name'];
}
$cat->closeCursor();
echo '<form method="post" action="accès/create_topic_post.php">';
echo '<label for="sujet">Sujet :';
echo '<input type="text" name="sujet" id="sujet" required autofocus>';
echo '</label>';
echo '<label for="cat">Catégories :';
echo '<select name="topic_name">';
echo "<option value=\"".$cat_name."\" >$cat_name </option>";
echo '</select>';
echo '<input type="submit" value="Envoyer">';
echo '</form>';
?>
【问题讨论】:
-
你必须为此使用循环。
-
欢迎来到 Stack Overflow。