gpt4 book ai didi

php - 下拉菜单 mysql PHP

转载 作者:行者123 更新时间:2023-11-30 00:31:57 26 4
gpt4 key购买 nike

我是 PHP 新手。我的下拉菜单程序有问题。我创建名为 id 和 name 的表。与 mysql 数据库连接这就是我想要的,当我在下拉菜单 1 上选择 id 1 时,然后在下拉菜单 2 中“仅显示”名称“ex:dk”和其他示例“id 2”= name :“James”....

     <?php
/*---START -----*/
$host ='localhost';
$user ='root';
$pass ='';
$db ='sqldumb';

$kon =mysql_connect($host, $user, $pass);
if(!$kon)
die('EROR '.mysql_error());
$dbkon =mysql_select_db($db);
if(!$dbkon)
die('EROR '.mysql_error());

/*-------END ------*/

$sql = '';
$result = mysql_query("SELECT * FROM cahkos");

$sql .= '<select>';
while($row = mysql_fetch_array($result))
{
$sql .= "<option value='".$row['id']."'>".$row['id']."</option>";
}
$sql .= '</select>';
?>


<?php
$sql1 = '';
$result = mysql_query("SELECT * FROM cahkos Where name = '.$row[id].' );

$sql1 .= '<select>';
while($row = mysql_fetch_array($result))
{
$pilihan1 .= "<option value='".$row['name']."'>".$row['name']."</option>";
}
$sql1 .= '</select>';
?>


<html>
<head></head>
<body>
<table align=center >
<tr>
<td font-size=100>choose ID</td>
<td><?php echo $sql;?></td>
</tr>
<tr>
<td font-size=100>choose Name</td>
<td><?php echo $sql;?></td>
</tr>
</table>
</body>

最佳答案

这个

$result = mysql_query("SELECT * FROM cahkos Where name  = '.$row[id].' );

应该是这个

$result = mysql_query("SELECT * FROM cahkos Where name  = '".$row['id']."'" );

关于php - 下拉菜单 mysql PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22440348/

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