高分求简单数据库查询问题

hizhi 2003-08-20 11:43:11
在查询里面输入 100-200的话,如果分别读取100 200 这两个数。
select jg between $a and $b
from cp
我PHP一窃不通,但上面交给我这个东东,让我搞定。。麻烦各位~~~~~
...全文
43 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
hizhi 2003-08-20
  • 打赏
  • 举报
回复
$oldstring="100-200";
$newstring=explode("-",$oldstring);
$a=$newstring[0];
$b=$newstring[1];
if ($a>($a+$b)/2)
{ max=$a;
min=$b;
}
else{
min=$b;
max=$a;
}

selecet xxx
from xx
where xx<=max and xx>=min
这样写对不对?
myblessu 2003-08-20
  • 打赏
  • 举报
回复
$arr = explode("-","100-200");
$a=$arr[0];
$b=$arr[1];

hizhi 2003-08-20
  • 打赏
  • 举报
回复
explode把输入的100-200分成$a=100和$b=200这两个数.
能具体点吗?
explode????
jsyqz 2003-08-20
  • 打赏
  • 举报
回复
查100语句

SELECT FROM `数据库表名称` WHERE 1 AND `序号字段(一般为id)` = 100

查200语句

SELECT FROM `数据库表名称` WHERE 1 AND `序号字段(一般为id)` = 200
jsyqz 2003-08-20
  • 打赏
  • 举报
回复
查100语句

FROM `数据库表名称` WHERE 1 AND `序号字段(一般为id)` = 100

查200语句

FROM `数据库表名称` WHERE 1 AND `序号字段(一般为id)` = 200

myblessu 2003-08-20
  • 打赏
  • 举报
回复
用explode把输入的100-200分成$a=100和$b=200这两个数.


然后用 select * form cp where jg='$a' or jg='$b'
bushido 2003-08-20
  • 打赏
  • 举报
回复
select * from cp where jg between $a and $b

hizhi 2003-08-20
  • 打赏
  • 举报
回复
啊,麻烦写个完全的给我好吗?谢谢。
myblessu 2003-08-20
  • 打赏
  • 举报
回复
你查询语句错了吧?
ustb 2003-08-20
  • 打赏
  • 举报
回复
//分解字符串,如果你是要找这两个数据的话
$oldstring="100-200";
$newstring=explode("-",$oldstring);
$a=$newstring['0'];
$b=$newstring['1'];
$sql="select * from cp where XX='$a' or XX='$b'";

//如果是要找他们之间的东东
$sql="select * from cp where XX between $a and $b";
myblessu 2003-08-20
  • 打赏
  • 举报
回复
<?php
$oldstring="100-200";
$newstring=explode("-",$oldstring);
$a=$newstring[0];
$b=$newstring[1];

if ($a>$b){
$sql="selecet xxx from xx where xx<=$a and xx>=$b";
}else if($a==$b){
$sql="selecet xxx from xx where xx='$a'";
}else{
$sql="selecet xxx from xx where xx<=$b and xx>=$a";
}

echo $sql;
?>

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧