使用php从下拉列表中获取值,从两个Mysql表中显示数据 [英] display data from two Mysql tables by getting values from drop down list using php

查看:110
本文介绍了使用php从下拉列表中获取值,从两个Mysql表中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表格国家/地区,其字段为

I have two tables countries, location whose fields are

_countries
    countryid(Primary Key)
    countryname

_location
    locationid(primarykey)
    locationname
    countryid(Foreign key from countries table)

使用JavaScript,AJAX和php完成每件事情,当用户从下拉列表中选择一个国家/地区时,每个国家/地区的位置将被移除,但是mysql查询不会工作
我正在使用下面的查询

Every thing is done using JavaScript,AJAX and php that when a user selects a country from drop down list, locations against each country will be displaced but the mysql query is not working I am Using the Below Query

$sql="SELECT _location.locationname, _countries.countryname FROM _location 
INNER JOIN _countries ON _location.countryid='".$q."'";

//$q is the countryid selected from drop down list i got it through javascript and php

下拉列表从国家表填入
我的问题是当用户从下拉列表中选择一个国家名称时,
将获取位置名称的mysql查询对每个国家的名字和显示这样的数据

The drop down list is populated from the countries table My Question is when a user selects a country name from the drop down list what will be the mysql query that fetch the location name against each country name and display data like this

||Location name||Country Name||
  Islamabad       Pakistan
  Karachi         Pakistan


推荐答案

 $sql = "SELECT l.locationname, c.countryname
FROM
_countries c
LEFT JOIN _location l ON c.countryid = l.countryid
WHERE c.countryid = ".(int)$q;

这篇关于使用php从下拉列表中获取值,从两个Mysql表中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆