mssql查询语句问题

nbzz505 2009-09-05 05:01:57
查询当isdel字段等于0时的记录

$strWhere="(isDel=\"0\") and Name like '% $strKeyWord %'";

if ($strWhere!="0"){
$strSQL="select * from contract where".$strWhere;
}else{
$strSQL="select * from contract where (isDel=\"0\")";
}

结果输出$strWhere 和 $strSQL 均为空,
提示:Warning: mssql_query() [function.mssql-query]: message: 第 1 行: 'where' 附近有语法错误。
大家帮忙看看是哪里写错了,谢谢
...全文
57 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
nbzz505 2009-09-05
  • 打赏
  • 举报
回复
谢谢问题解决,应该是这个where (isDel='0')
dzxccsu 2009-09-05
  • 打赏
  • 举报
回复

$strWhere=" isDel='0' and Name like '% $strKeyWord %'";<==注意前面要空一个字符。

if (!empty($strKeyWord)){//你这个判断什么?判断$strWhere字符长度?
$strSQL="select * from contract where".$strWhere;
}else{
$strSQL="select * from contract where isDel='0'";
}



[Quote=引用 2 楼 nbzz505 的回复:]
if ($strWhere!="0") 这个判断$strWhere 是否为空
[/Quote]这个字段你已经定义有字符,所以永远不为空!
nbzz505 2009-09-05
  • 打赏
  • 举报
回复
Warning: mssql_fetch_row(): supplied argument is not a valid MS SQL-result resource in C:\Apache2\htdocs\contract\admin\Browse.php on line 56
select * from contract where
Warning: mssql_query() [function.mssql-query]: message: 第 1 行: 'where' 附近有语法错误。 (severity 15) in C:\Apache2\htdocs\contract\admin\Browse.php on line 83
nbzz505 2009-09-05
  • 打赏
  • 举报
回复
还是同样的错误
nbzz505 2009-09-05
  • 打赏
  • 举报
回复
if ($strWhere!="0") 这个判断$strWhere 是否为空
dzxccsu 2009-09-05
  • 打赏
  • 举报
回复

$strWhere=" (isDel='0') and Name like '% $strKeyWord %'";<==注意前面要空一个字符。

if ($strWhere!="0"){//你这个判断什么?判断$strWhere字符长度?
$strSQL="select * from contract where".$strWhere;
}else{
$strSQL="select * from contract where (isDel='0')";
}

21,891

社区成员

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

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