简体   繁体   English

查询工作在phpmyadmin中,但不在页面上

[英]Query Works in phpmyadmin but not on the page

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®%' 这是我的SQL查询: SELECT * FROM txp_file WHERE filename LIKE '%Fast®%' OR description LIKE '%Fast®%'

In phpmyadmin, this brings back the results I want. 在phpmyadmin中,这会带回我想要的结果。 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. 我尝试使用substring省略特殊商标符号,我尝试了100万种不同的变体,但没有结果。 Here is my php code: 这是我的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';

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? 任何人都可以发现此代码有什么问题吗?

PS $querytitle is a global variable. PS $ querytitle是全局变量。 I have echoed it and it comes up just the way it should. 我已经回应了它,它以它应该的方式出现。

You probably haven't set the character set for the connection. 您可能尚未设置连接的字符集。 Use the command: 使用命令:

SET NAMES utf8;

or whatever character set you are using. 或您使用的任何字符集。 To find the default character set of the database and the connection you can execute this command: 要查找数据库和连接的默认字符集,可以执行以下命令:

USE yourdb;
SHOW VARIABLES LIKE "%coll%";

It will show you a list of collations for the server, the database and the connection. 它将显示服务器,数据库和连接的排序规则列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM