我有 sql 查询来搜索这样的关键字
if (isset($_POST['no_peserta_mhs_2015'])) {
$colname_rec_mhs_2015 = $_POST['no_peserta_mhs_2015'];
}
mysql_select_db($database_connect, $connect);
$query_rec_mhs_2015 = sprintf("SELECT * FROM mhs_2015 WHERE no_peserta_mhs_2015 = %s or nama_mhs_2015 like %s ", GetSQLValueString($colname_rec_mhs_2015, "text"), GetSQLValueString($colname_rec_mhs_2015, "text"));
如果我使用 nama_mhs_2015 like %s
搜索名称时遇到问题,我必须输入完整的名称,我只想输入名称的一部分,我的查询可以在我的查询中找到整个名称表数据库。有帮助吗?
最佳答案
如果可行,试试这个:
来自:
$query_rec_mhs_2015 = sprintf("SELECT * FROM mhs_2015 WHERE no_peserta_mhs_2015 = %s or nama_mhs_2015 like %s ", GetSQLValueString($colname_rec_mhs_2015, "text"), GetSQLValueString($colname_rec_mhs_2015, "text"));
To: //我已经将 %s 更改为 '/%'
$query_rec_mhs_2015 = sprintf("SELECT * FROM mhs_2015 WHERE no_peserta_mhs_2015 = '%s' OR nama_mhs_2015 like '%s' ", GetSQLValueString($colname_rec_mhs_2015, "text"), GetSQLValueString($colname_rec_mhs_2015, "text"));
关于php - 如何使用 %s 在 mysql 中使用 'like' 代码查询搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31955522/