【发布时间】:2014-04-06 16:26:29
【问题描述】:
我有一个表格可以在表格中插入一些数据。我正在尝试使用 PDO 来做到这一点。
我的数据库中有一个表,其中包含类别和子类别。该表具有以下列:
******
id(自动递增)
parent_id(0 代表类别另一个数字代表子类别)
nume_categorie(带有类别/子类别名称的varchar)
desc_categorie(带有类别描述的 varchar)。
在我的表单中,我有一个选择输入来从 DB 中获取一个类别。
如何从列出的类别(列出的动态)中获取 id?
<select id="categorie" name="categorie">
<?php
$stmt = $db->prepare('Select nume_categorie FROM categories WHERE parent_id=0 order by id');
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo '<option>'.$row['nume_categorie'].'</option>';
}
?>
</select>
我的发帖查询是 $categorie 。 这个变量是:
$categorie = htmlentities(trim($_POST['categorie']));
如果可能有另一个选择表单,其中列出了从上面选择的类别中列出的子类别。 最好的问候。
【问题讨论】: