查询在 phpmyadmin 中有效,但在页面上无效
我尝试过各种各样的事情,并花了几个小时来做这件事,如果有人能告诉我我在做什么,我真的很高兴。
这是我的 SQL 查询: SELECT * FROM txp_file WHERE filename LIKE '%Fast®%' OR description LIKE '%Fast®%'
在 phpmyadmin 中,这会返回我想要的结果。在页面上,查询显然有效,但没有得到结果。我尝试使用子字符串来省略特殊商标符号,我尝试了一百万种不同的变体,但没有得到结果。这是我的 php 代码:
$sql = "SELECT * FROM txp_file WHERE filename LIKE '%$querytitle%' OR description LIKE '%$querytitle%'";
$query = mysql_query($sql) or die(mysql_error());
$result = mysql_fetch_array($query);
if ($result){
echo "<a href='#'>$querytitle</a>";
}
else
echo 'nil';
与数据库的连接已经存在,因此在这种情况下我不需要再次执行此操作。谁能发现这段代码有什么问题吗?
PS $querytitle 是一个全局变量。我已经回应了它,它就按照它应该的方式出现了。
I have tried all kinds of things and spent hours doing this and would really like it if someone can tell me what I'm doing.
This is my SQL query:SELECT * FROM txp_file WHERE filename LIKE '%Fast®%' OR description LIKE '%Fast®%'
In phpmyadmin, this brings back the results I want. On the page, the query apparently works but gets no result. I have tried to use substring to omit the special trademark symbol, I have tried a million different variations but I get no result. Here is my php code:
$sql = "SELECT * FROM txp_file WHERE filename LIKE '%$querytitle%' OR description LIKE '%$querytitle%'";
$query = mysql_query($sql) or die(mysql_error());
$result = mysql_fetch_array($query);
if ($result){
echo "<a href='#'>$querytitle</a>";
}
else
echo 'nil';
The connection to the database is already there so I don't need to do it again in this case. Can anyone find anything wrong with this code?
P.S. $querytitle is a global variable. I have echoed it and it comes up just the way it should.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能尚未设置连接的字符集。使用命令:
或您正在使用的任何字符集。要查找数据库和连接的默认字符集,您可以执行以下命令:
它将显示服务器、数据库和连接的排序规则列表。
You probably haven't set the character set for the connection. Use the command:
or whatever character set you are using. To find the default character set of the database and the connection you can execute this command:
It will show you a list of collations for the server, the database and the connection.