php通过标题查询mysql数据库不显示结果,代码如下
刚学mysql超级菜鸟,数据库3个字段id,title,content,里面有一条内容------------------------------------------...
刚学mysql超级菜鸟,数据库3个字段id,title,content,里面有一条内容
-----------------------------------------------------------------------------
id title content
1 韩海警用橡皮弹打死中国渔民 我们要以牙还牙!!!!
-----------------------------------------------------------------------------
<?php
mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query('SET NAMES gb2312');
$sql = 'SELECT `content` FROM `db_test` WHERE `title` LIKE CONVERT(_utf8 \'韩海警用橡皮弹打死中国渔民\' USING gbk) COLLATE gbk_chinese_ci';
$searchresult=mysql_query($sql);
//var_dump($searchresult); 用var_dump检查资源显示是resource(4) of type (mysql result)
while($row = mysql_fetch_array($searchresult)){
echo $row['content'];
}
?>为什么不显示内容啊??????但是通过id字段查询会显示结果,在线等
"SELECT `content` FROM `db_test` WHERE `title` LIKE '韩海警用橡皮弹打死中国渔民'"
我自己解决了,这样就可以 展开
-----------------------------------------------------------------------------
id title content
1 韩海警用橡皮弹打死中国渔民 我们要以牙还牙!!!!
-----------------------------------------------------------------------------
<?php
mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query('SET NAMES gb2312');
$sql = 'SELECT `content` FROM `db_test` WHERE `title` LIKE CONVERT(_utf8 \'韩海警用橡皮弹打死中国渔民\' USING gbk) COLLATE gbk_chinese_ci';
$searchresult=mysql_query($sql);
//var_dump($searchresult); 用var_dump检查资源显示是resource(4) of type (mysql result)
while($row = mysql_fetch_array($searchresult)){
echo $row['content'];
}
?>为什么不显示内容啊??????但是通过id字段查询会显示结果,在线等
"SELECT `content` FROM `db_test` WHERE `title` LIKE '韩海警用橡皮弹打死中国渔民'"
我自己解决了,这样就可以 展开
3个回答
展开全部
改成这样,看看行不行
<?php
mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query('SET NAMES gb2312');
$title = iconv("utf-8","gb2312","韩海警用橡皮弹打死中国渔民");
$sql = 'SELECT `content` FROM `db_test` WHERE `title` LIKE '%".$title."%';
$searchresult=mysql_query($sql);
//var_dump($searchresult); 用var_dump检查资源显示是resource(4) of type (mysql result)
while($row = mysql_fetch_array($searchresult)){
echo $row['content'];
}
?>
<?php
mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query('SET NAMES gb2312');
$title = iconv("utf-8","gb2312","韩海警用橡皮弹打死中国渔民");
$sql = 'SELECT `content` FROM `db_test` WHERE `title` LIKE '%".$title."%';
$searchresult=mysql_query($sql);
//var_dump($searchresult); 用var_dump检查资源显示是resource(4) of type (mysql result)
while($row = mysql_fetch_array($searchresult)){
echo $row['content'];
}
?>
追问
"SELECT `content` FROM `db_test` WHERE `title` LIKE '韩海警用橡皮弹打死中国渔民'"
我自己解决了,这样就可以
你的代码单引号和和双引号出来问题,呵呵。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询