我想通过搜索查询显示主表中的全部数据,并按名称搜索城市和州,并在主表中输入城市和州ID而不是名称。
PHP API 中的 phpmyadmin MySQL 数据库。
if(!empty($state_id))
{
$condition .="sangh_directory.state like '$state_id%'";
}
if(!empty($city_id))
{
$condition .="and sangh_directory.city like '$city_id%'";
}
if(!empty($searchsangh))
{
$condition .="sangh_directory.sangh_name like '$searchsangh%'";
}
$DirectoryDetailsQuery=$con->select_query("sangh_directory","*","inner join city on city.city_id=sangh_directory.city inner join country ON country.country_id=sangh_directory.country inner join state ON state.state_id=sangh_directory.state where $condition");
选择查询表名称时存在一些错误:sangh_directoryYou SQL 语法有错误;请查看与您的 MySQL 服务器版本对应的手册,了解在第 1 行的"和 sangh_directory.city 如 'Ahme%'"附近使用的正确语法
试试这个:
$condition = "1=1";
if(!empty($state_id)) {
$condition .=" and sangh_directory.state like '$state_id%'";
}
if(!empty($city_id)) {
$condition .=" and sangh_directory.city like '$city_id%'";
}
if(!empty($searchsangh)) {
$condition .=" and sangh_directory.sangh_name like '$searchsangh%'";
}
$DirectoryDetailsQuery=$con->select_query("sangh_directory","*","inner join city on city.city_id=sangh_directory.city inner join country ON country.country_id=sangh_directory.country inner join state ON state.state_id=sangh_directory.state where $condition");
如果这在语法上不正确,我很抱歉,我希望你能理解它的要点。
如果你正在制作一个公开的网站,请观看这个视频或阅读任何其他关于sql注入的内容,正如@Dharman已经提出的那样。
并阅读有关保护网站的其他主题。