简单的sql查询,纠结... select * from table where content like '%商店名字%' 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 接楼上,如果不能实现你所谓的模糊查询。。只能自定义一个split函数了。。你可以查下mysql split()。相信能解决你的问题。 我不太懂你意思哎,你table是content吧?那没有属性名?比如商店名字是shop_name之类的? 问题就在这里...商店的属性并没有单独的字段,都是按照格式存在content的字段里面 这样行吗slect * from A where content like "%=商店名字|%" 表设计的有点难度... 如果数据量不大 办法就是取出全部的content 然后再根据"|" 拆分成数组... 然后再来对比... 在mysql里写个方法吧 你的记录里 所有等号后面都是商店名字在方法里查找 <?php include "conn/conn.php";?><?php if($_POST["submit"]<>""){ $txt_tj=trim($_POST["txt_tj"]); $strs=explode("*",$txt_tj); while(list($name,$value)=each($strs)){ $sql=mysql_query("select * from tb_book where synopsis like '%$value%' or bookname like '%$value%' order by id desc"); $info=mysql_fetch_array($sql); }} if($info){ do{ ?> <tr> <td height="23"><span class="STYLE1"> ◎ <?php $string=str_ireplace($txt_tj,"<font color='#FF0000'><strong>$txt_tj</strong></font>",$info[bookname]);echo $string;?> </span></td> </tr> <tr> <td height="22" class="STYLE1"> <?php $strings=$_POST["txt_tj"];$string=str_ireplace($_POST["txt_tj"],"<font color='#FF0000'><strong>$strings</strong></font>",$info[synopsis]);echo $string;?></td> </tr> <?php }while($info=mysql_fetch_array($sql)); }else{ ?> <tr> <td><span class="STYLE2">对不起,您检索的信息不存在!</span></td> </tr> <?php } ?> </table> <br></td> </tr> </table> sql查询语句里加正则表达式可以解决例如:select * from table where content REGEXP ''具体的正则我不会写,你可以上网搜索一下。 大概应该是这样:select * from table where content REGEXP '^[|{$xxx}|]$'{$xxx} 这个是你的查询变量这个正则的意思是模糊匹配 第一个“|”到第二个“|”之间的内容与查询变量进行匹配。我也不知道这个正则写的对不对,大体是这个意思,你再去搜搜。 select * from table where content REGEXP '^|{$xxx}|$'这个是对的 表结构的设计也太牛叉了吧,第一次看到这样设计的.如果为了以后的方便最好现在就改表结构,我想到的笨方法:select * from table where content like '%商店名字%'这样查询个大概,然后再在程序里面去遍历数组判断... php获取google来源关健词 Linux下HTTP_RAW_POST_DATA不能用,有什么可以替代它的呢? (急)请教一下有没有人会把Excel中的数据导入到MySql啊 session问题 如何查找指定键的路径 一个文件夹内存放过多文件是否可行 兄弟门,帮帮忙啊!急!!! 如何去掉换行符? 啊,7456 给我一根绳子:phpmyadmin建库!!!! mysql如何把datetime类型转成date类型? 请问为什么对象是在页面加载完毕才销毁! get发送返回部分乱码
我不太懂你意思哎,你table是content吧?那没有属性名?比如商店名字是shop_name之类的?
slect * from A where content like "%=商店名字|%"
如果数据量不大
办法就是取出全部的content
然后再根据"|" 拆分成数组...
然后再来对比...
在mysql里写个方法吧 你的记录里 所有等号后面都是商店名字在方法里查找
<?php
if($_POST["submit"]<>""){
$txt_tj=trim($_POST["txt_tj"]);
$strs=explode("*",$txt_tj);
while(list($name,$value)=each($strs)){
$sql=mysql_query("select * from tb_book where synopsis like '%$value%' or bookname like '%$value%' order by id desc");
$info=mysql_fetch_array($sql);
}}
if($info){
do{
?>
<tr>
<td height="23"><span class="STYLE1"> ◎
<?php
$string=str_ireplace($txt_tj,"<font color='#FF0000'><strong>$txt_tj</strong></font>",$info[bookname]);
echo $string;
?>
</span></td>
</tr>
<tr>
<td height="22" class="STYLE1"> <?php
$strings=$_POST["txt_tj"];
$string=str_ireplace($_POST["txt_tj"],"<font color='#FF0000'><strong>$strings</strong></font>",$info[synopsis]);
echo $string;
?></td>
</tr>
<?php }while($info=mysql_fetch_array($sql));
}else{
?>
<tr>
<td><span class="STYLE2">对不起,您检索的信息不存在!</span></td>
</tr>
<?php } ?>
</table>
<br></td>
</tr>
</table>
例如:select * from table where content REGEXP ''具体的正则我不会写,你可以上网搜索一下。
select * from table where content REGEXP '^[|{$xxx}|]$'
{$xxx} 这个是你的查询变量这个正则的意思是模糊匹配 第一个“|”到第二个“|”之间的内容与查询变量进行匹配。
我也不知道这个正则写的对不对,大体是这个意思,你再去搜搜。
这个是对的
我想到的笨方法:select * from table where content like '%商店名字%'这样查询个大概,
然后再在程序里面去遍历数组判断...