在mysql连接查询中使用变量

时间:2014-01-27 08:59:05

标签: php jquery mysql

在这个查询中,当我手动设置cities.city_id的值时,它工作正常,但是当我使用像$ adcity这样的变量时它没有显示任何输出。任何人都可以帮助我在这个查询中使用变量。

在这方面,有些人可以帮助我。

$sql = 'SELECT advertisments.ad_id,
         advertisments.ad_title, 
        advertisments.ad_title_slug,
         advertisments.ad_type, 
        advertisments.last_date,
         organizations.organization_logo, 
        cities.city_id, 
        cities.city_name, 
        newspapers.newspaper_logo, 
        newspapers.newspaper_name
FROM advertisments, organizations, cities, newspapers
WHERE advertisments.organization_id = organizations.organization_id
AND advertisments.city_id = cities.city_id
AND advertisments.newspaper_id = newspapers.newspaper_id
AND ad_type = "Admissions"
AND cities.city_id = "$adcity"
        ORDER BY ad_id DESC 
        LIMIT 10';
        $open_admissions = mysql_query($sql);

1 个答案:

答案 0 :(得分:0)

现在你试试。

$sql = 'SELECT advertisments.ad_id,
         advertisments.ad_title, 
        advertisments.ad_title_slug,
         advertisments.ad_type, 
        advertisments.last_date,
         organizations.organization_logo, 
        cities.city_id, 
        cities.city_name, 
        newspapers.newspaper_logo, 
        newspapers.newspaper_name
FROM advertisments, organizations, cities, newspapers
WHERE advertisments.organization_id = organizations.organization_id
AND advertisments.city_id = cities.city_id
AND advertisments.newspaper_id = newspapers.newspaper_id
AND ad_type = "Admissions"
AND cities.city_id = "'.$adcity.'"
        ORDER BY ad_id DESC 
        LIMIT 10';
        $open_admissions = mysql_query($sql);

添加。 cities.city_id = "'.$adcity.'"喜欢这样。

希望它对你有用。如果它不起作用。告诉我。

由于