我正在使用 PHP 和 MYSQL 开发一个网站。我制作了一个表格来为博客添加类别并将其存储在类别表中。现在我想以另一种形式的博客访问下拉菜单中的这些类别。谁能解决我的问题?
这是表单的代码:
<html>
<head>
<title>Create a Blog!</title>
</head>
<body>
<?php
include_once ('BlogClass.php');
$j = new Blog();
$ans = array();
$ans = $j->DisplayCategories();
?>
<form name="BlogTopic" action="BlogTopicProcess.php" method="post" onSubmit="return validateForm()">
topic_cat :
<select name="topic_cat">
<?php
for ( $i = 0; $i < count( $ans ); $i++ ) {
?>
<option value="<?php echo($ans[$i]['Category']);?>"><?php echo($ans[$i] ['Category']);?></option>
<? php
}
?>
</select>
<label><strong>topic_id:</strong></label>
<input name="topic_id" type="text"/><br>
<label><strong>topic_subject:</strong></label>
<input name="topic_subject" type="text"/><br>
<label><strong>topic_date:</strong></label>
<input name="topic_date" type="text"/><br>
<label><strong>topic_by:</strong></label>
<input name="topic_by" type="text"/><br>
<input type="checkbox" name="terms" />
I agree to the <a href="#">terms & conditions</a> <br>
<input type="submit" value="Create Topic" /><br>
</form>
</body>
</html>
功能DisplayCategory()
public function DisplayCategory() {
$connection=$this->Con->connectDb();
$data=array();
$sql="select * from categories";
$query=mysql_query($sql);
$numrows=mysql_num_rows($query);
if ($numrows!=0) {
while ($a=mysql_fetch_array($query))
$data[]=$a;
}
mysql_close($connection);
return $data;
}