douerlin4366 2015-02-02 12:05
浏览 33

如何使用比较运算符和文本数据?

How to use Comparison operator with text data ?

This is my table

http://image.ohozaa.com/i/51c/zBed4I.png

And this is my code.

<?PHP
include("connect.php");
$sql = "SELECT * FROM test_db WHERE number >= '3' AND number <= '5' order by id asc";
$result = mysql_query($sql);
$datas=mysql_fetch_array($result);{
$id = stripslashes(str_replace('
', '<br>',($datas['id'])));
}
?>

After test code, I will get result id 1 and 2

How can i do that ?

  • 写回答

1条回答 默认 最新

  • dongyan7851 2015-02-02 12:16
    关注

    You could always change your table structure so that one value per column is stored. BUT work-around for your table structure could be this:

    instead of '='use LIKE moreover, use something like this:

    where number like '*[3-5]*'

    please lookup for regex in sql, I am not very good in regex. but the basic idea is to use LIKE query and try match any pattern that starts with anything but has atleast either 3 or 4 or 5 in between and then has anything after that.

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改