本文介绍了根据提交的选择选项显示数据库中的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 我正在寻找一些指导。我想列出依赖于从选择菜单中选择的内容的数据行。理想情况下,我希望在没有重新加载的情况下出现在同一页面上(AJAX?)。 到目前为止我有这个: < 表格 action = animals.php 方法 = 发布 > < fieldset > < 选择 > < 选项 value = 种类 > 种类< / option > < 选项 value = 附件 > 附件< ; / option > < 选项 value = animal > 动物< / option > < / select > < 输入 type = 提交 / > < / fieldset > < / fo rm > 和PHP代码: b $ b <?php 包括' dbconnect.php'; if(isset($ _ POST [' value'])){ if($ _ POST [' value'] == ' 种类'){ $ query = SELECT Speciesname FROM SPECIES内部联接ANIMAL ANIMAL.Species = SPECIES.Speciesid; } elseif($ _ POST [' value'] == ' enclosure'){ $ query = SELECT Enclosurename FROM ENCLOSURE内部联接ANIMAL ANIMAL.Enclosure = ENCLOSURE.Enclosureid; } 其他 { $ query = SELECT Animalname FROM ANIMAL; } $ sql = mysql_query($ query); while ($ row = mysql_fetch_array($ query)){ $ species = $ row [ Speciesname]; $ enclosure = $ row [ Enclosurename ]; $ animal = $ row [ Animalname ]; } } ?> 我需要回应一组结果,但我不知道如何执行此操作,具体取决于从表单提交的内容。例如。如果用户选择了物种,所有物种都会从数据库中显示出来,而不是别的。 谢谢。解决方案 _POST [' value'])){ if( _POST [' value'] == ' 种类'){ query = SELECT SPECiesname FROM SPECIES内部联接ANIMAL ANIMAL.Species = SPECIES.Speciesid; } elseif( Hi all,Im looking for some guidance. I want to list rows of data that is dependant on what was selected from the select menu. Ideally I'd like this to appear on the same page without a reload (AJAX?).So far I have this:<form action="animals.php" method="post"> <fieldset> <select> <option value="species">Species</option> <option value="enclosure">Enclosure</option> <option value="animal">Animal</option> </select> <input type="submit" /> </fieldset> </form>And the PHP code:<?phpinclude 'dbconnect.php';if(isset($_POST['value'])) { if($_POST['value'] == 'species') { $query = "SELECT Speciesname FROM SPECIES inner join ANIMAL on ANIMAL.Species=SPECIES.Speciesid"; } elseif($_POST['value'] == 'enclosure') { $query = "SELECT Enclosurename FROM ENCLOSURE inner join ANIMAL on ANIMAL.Enclosure=ENCLOSURE.Enclosureid"; } else { $query = "SELECT Animalname FROM ANIMAL"; } $sql = mysql_query($query); while ($row = mysql_fetch_array($query)){ $species = $row["Speciesname"];$enclosure = $row["Enclosurename"];$animal = $row["Animalname"]; } } ?>I need to echo 1 set of results but I am unaware of how to do this depending on what was submitted from the form. E.g. If the user selected species, all species will be shown from the database, and nothing else.Thanks. 解决方案 _POST['value'])) { if(_POST['value'] == 'species') { query = "SELECT Speciesname FROM SPECIES inner join ANIMAL on ANIMAL.Species=SPECIES.Speciesid"; } elseif( 这篇关于根据提交的选择选项显示数据库中的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 23:55