【发布时间】:2012-11-14 03:50:48
【问题描述】:
可能重复:
How can I refresh a detail select list when my master select changes using AJAX
我只是在一段时间后再次开始学习 PHP,在环顾四周后认为我需要使用 JS/ajax 来实现这一点,我打算在我对 PHP 更加熟悉之后了解更多。我想学习如何为我现在正在做的一些事情做到这一点。
我有一个父项目表,我将其显示为链接列表。单击父项时,我希望单击的父项的子项显示在另一个列表中。我可以使用简单的查询来显示 2 个列表,我只是不知道如何在单击时更新页面/sql 查询。
<?php require ('connection.inc.php'); ?>
<div id="lists">
<h3>Lists</h3>
<?php
$lists = mysql_query("SELECT * FROM lists")
or die(mysql_error());
while($info = mysql_fetch_array( $lists ))
{
echo "<a href=\"#\">".$info['ListName']."</a><br />";
}
?>
</div>
<div id='listitems'>
<h3>List <?php $parent=2; echo $parent?> Items</h3>
<?php
$listitems = mysql_query("SELECT * FROM listitems WHERE parent=$parent")
or die(mysql_error());
while($info = mysql_fetch_array( $listitems ))
{
echo $info['itemName']."<br />";
}
?>
</div>
【问题讨论】:
-
你已经用答案标记了问题:ajax
-
欢迎来到 Stack Overflow! Please, don't use
mysql_*functions in new code。它们不再维护,deprecation process 已开始使用。看到red box?改为了解prepared statements,并使用PDO 或MySQLi - this article 将帮助您决定哪个。如果你选择 PDO,here is a good tutorial. -
看看这个问题/答案:stackoverflow.com/questions/5914993/…
标签: php javascript mysql ajax