gpt4 book ai didi

php - 在mysql连接查询中使用变量

转载 作者:行者123 更新时间:2023-11-30 00:45:40 25 4
gpt4 key购买 nike

在这个查询中,当我手动放置city.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);

最佳答案

现在你试试。

$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.'" 像这样。

希望它对你有用。如果它不起作用。通知我。

谢谢

关于php - 在mysql连接查询中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21376595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com