gpt4 book ai didi

php/mysql + 填充 3 个下拉菜单

转载 作者:行者123 更新时间:2023-11-30 23:21:55 25 4
gpt4 key购买 nike

大家好,我正在开发一个页面,我在其中填充了多个包含从数据库中检索到的数据的下拉菜单,但问题是我只能填充一个下拉菜单 如果有人能帮助我,如何能够填充多个 plz

func.inc.php

<?php
require_once('db.inc.php');

function connect(){
mysql_connect(DB_Host, DB_User ,DB_Pass )or die("could not connect to the database" .mysql_error());

mysql_select_db(DB_Name)or die("could not select database");

}
function close(){

mysql_close();

}

function countryQuery(){

$countryData = mysql_query("SELECT * FROM country");

while($record = mysql_fetch_array($countryData)){

echo'<option value="' . $record['country_name'] . '">' . $record['country_name'] . '</option>';

}

}

function specializationQuery(){

$specData = mysql_query("SELECT * FROM specialization");

while($recordJob = mysql_fetch_array($specData)){

echo'<option value="' . $recordJob['specialization_name'] . '">' . $recordJob['specialization_name'] . '</option>';

}


}
?>

索引.php

<?php
require_once('func.inc.php');
connect();


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>testDroplistdown</title>
</head>

<body>
<p align="center">
<select name="dropdown">
<?php countryQuery(); ?>
</select>
<?php close(); ?>
</p>
<p align="left">
<select name="dropdown2">
<?php specializationQuery(); ?>
</select>
<?php close(); ?>
</p>


</body>
</html>

最佳答案

您似乎正在关闭连接而不是重新连接。删除第一个 close() 并尝试一下

关于php/mysql + 填充 3 个下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15128671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com