本文介绍了如何创建下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建下拉菜单,这个下拉菜单是关于国家的名称,所以当用户例如选择国家A时,所有与国家A相关的帖子都会显示出来。



所以我的问题是我需要为每个国家创建一个单独的PHP文件,以获得与特定国家相关的帖子?



 < / p> 

选择name =myCountry>
< option>国家A< / option>
< option>国家B< /选项>
< option> etc lol< / option>
< / select>

然后将表单指向您的PHP处理文件,然后在那里执行类似操作。

  $ selectedCounty = $ _GET ['myCountry']; / /这将从该国家下拉列表中选择的值分配到一个可用的变量。 

然后u查询数据库。
让我们假设您有一个名为countries的数据库表和一个列出了名为myCountries的列。

  $ selectCountryQS = SELECT * FROM countries WHERE myCountries ='$ selectedCountry'; 

然后将其付诸实践

<$ p $ (这里的'connection variable',$ selectCountryQS)或者死('error mssg'。mysqli_error(conection var here));

然后设置一个while循环来抓取您想要的所有帖子数据。

  while($ row = mysqli_fetch_array($ selectCountryDoIt)){
echo $ row ['column data to display here'];
}

这会给你你所需要的。
希望这有助于。祝你好运

i'm trying to create dropdown menu, this drop down menu is about name of countries, so when the user for example choose country A then all the posts that are associated with country A will be displayed.

So my question is do i need to create a separate PHP file for every country in order to get the posts that are associated to a particular country?

解决方案

No you would create your dropdown as usual with

<select name="myCountry">
     <option>Country A</option>
     <option>Country B</option>
     <option>etc lol</option>
</select>

Then have your form point to your PHP processing file, and in there you would do something like.

$selectedCounty = $_GET['myCountry']; //This assigns the selected value from that country dropdown into a usable variable.

Then u query the database.Lets assume you have a database table called "countries" and a column with the countries listed called "myCountries".

$selectCountryQS = SELECT * FROM countries WHERE myCountries = '$selectedCountry';

Then put it into action

$selectCountryDoIt = mysqli_query('connection variable here', $selectCountryQS ) or die('error mssg'. mysqli_error(conection var here));

Then set a while loop that will grab ALL the posts data that you wanted.

while($row = mysqli_fetch_array($selectCountryDoIt)){
  echo $row[' your column data to display here'];
}

This will give you what you need.Hope this helps. Good luck

这篇关于如何创建下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 03:14