mysql 查询中的动态值
我试图使用下面的查询获取结果,每个加盟商的 idRegion 在数据库中记录为 1,2,3,4,所以我想要的是显示 idRegion 2 的所有加盟商。我通过 $_Get 获取 idRegion。这仅显示昏迷前的第一个数字,我认为它应该准备好整个字符串 1,2,3,4 ?当我使用静态值时有效吗?
$colname_franchisee = "-1";
if (isset($_GET['id'])) {
$colname_franchisee = $_GET['id'];
}
$query_franchisee = sprintf("SELECT * FROM franchise WHERE stiShowInLinks = 'Y' AND idRegion LIKE '%s%' ORDER BY stiName ASC", $colname_franchisee);
I am trying to get result using below query, idRegion is recorded in database as 1,2,3,4 for each franchisee, so what I want is to display all franchisees with idRegion 2. I am getting idRegion via $_Get. this display only first digit before coma, I think so it should ready whole string 1,2,3,4 ? When I am working with static values that works?
$colname_franchisee = "-1";
if (isset($_GET['id'])) {
$colname_franchisee = $_GET['id'];
}
$query_franchisee = sprintf("SELECT * FROM franchise WHERE stiShowInLinks = 'Y' AND idRegion LIKE '%s%' ORDER BY stiName ASC", $colname_franchisee);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽管我不喜欢您的数据库设计,但这应该可行:
sprintf 函数将
%
字符视为格式说明符,并以特殊方式处理接下来的几个字符。为了按字面意思使用%
字符,您必须使用%%
。因此,在 sprintf 之后,您的查询将变为:This should work although I do not like your database design:
The sprintf function treats the
%
character as a format specifier and treats at the next few characters in a special way. In order to use the%
character literally, you must use%%
. So after sprintf, your query becomes: