要把SQL的WHERE拼成这样才能查出来 function searchStr() { var s1="infoName"; var s2="infoId"; var s3="str2"; var s4="infoType"; var s5="infoDescription"; var s6="infoValue"; var final="groupinnerid='<%=id%>'"; var str="";
if(document.all[s1].value!="") { str = s1 +" like '%"+ document.all[s1].value + "%'" + " and "; } if(document.all[s2].value!="") { str = str +s2 +" like '%" + document.all[s2].value + "%'" + " and "; } if(document.all[s3].value!="") { str = str +s3 +" like '%" + document.all[s3].value + "%'" + " and "; } if(document.all[s4].value!="") { str = str +s4 +" like '%" + document.all[s4].value + "%'" + " and "; } if(document.all[s5].value!="") { str = str +s5 +" like '%" + document.all[s5].value + "%'" + " and "; } if(document.all[s6].value!="") { str = str +s6 +" like '%" + document.all[s6].value + "%'" + " and "; } str=str+final; //alert(str); document.all["whereStr"].value=str; document.all["currentPage"].value="1"; document.forms[0].action="ListDeployinfo.jsp"; document.forms[0].submit(); }
//System.out.println(sh); if(sh != null && sh.length() > 0 && (!"地级市".equals(sh))){ if(where.length() <= 0){ where = " where province ='" + sh +"'"; }else{ where += " and province ='" + sh +"'"; } }
String sql = "(select coname,homePage,lxr,fax,cotype,mob,tel,address,enid from copay " + where + " order by clickless desc limit 10000)" + "union all"+ "(select coname,homePage,lxr,fax,cotype,mob,tel,address,enid from 40bigroad1 " + where +")"; System.out.println(sql);我把sql语句打印出来,在查询分析器中能正确的显示
function searchStr()
{
var s1="infoName";
var s2="infoId";
var s3="str2";
var s4="infoType";
var s5="infoDescription";
var s6="infoValue";
var final="groupinnerid='<%=id%>'";
var str="";
if(document.all[s1].value!="")
{
str = s1 +" like '%"+ document.all[s1].value + "%'" + " and ";
}
if(document.all[s2].value!="")
{
str = str +s2 +" like '%" + document.all[s2].value + "%'" + " and ";
}
if(document.all[s3].value!="")
{
str = str +s3 +" like '%" + document.all[s3].value + "%'" + " and ";
}
if(document.all[s4].value!="")
{
str = str +s4 +" like '%" + document.all[s4].value + "%'" + " and ";
}
if(document.all[s5].value!="")
{
str = str +s5 +" like '%" + document.all[s5].value + "%'" + " and ";
}
if(document.all[s6].value!="")
{
str = str +s6 +" like '%" + document.all[s6].value + "%'" + " and ";
}
str=str+final; //alert(str);
document.all["whereStr"].value=str;
document.all["currentPage"].value="1";
document.forms[0].action="ListDeployinfo.jsp";
document.forms[0].submit();
}
比我快6秒哦
csdn
一个字
快
<form name="form1" method="post" action="companyAction.do?method=find">
<select id=s1 name=s>
<option selected>省份</option>
</select>
<select id=s2 name=sh>
<option selected>地级市</option>
</select>
关键字
<input type="text" name="cotypeSY"> //cotypeSY是"关键"字段
<input type="submit" name="Submit" value="提交">
<input type="hidden" name="temp" value="0">
</form>
</body>sql语句代码:String ipage = request.getParameter("page");
String where = "";
if(request.getParameter("page") == null || request.getParameter("page").length() <= 0){
ipage = "1";
}
if(cotypeSY != null && cotypeSY.length() >0 ){
where += " where cotypeSY like '%" + cotypeSY + "%' ";
}
//System.out.println(sh);
if(sh != null && sh.length() > 0 && (!"地级市".equals(sh))){
if(where.length() <= 0){
where = " where province ='" + sh +"'";
}else{
where += " and province ='" + sh +"'";
}
}
String sql = "(select coname,homePage,lxr,fax,cotype,mob,tel,address,enid from copay " + where + " order by clickless desc limit 10000)" +
"union all"+
"(select coname,homePage,lxr,fax,cotype,mob,tel,address,enid from 40bigroad1 " + where +")";
System.out.println(sql);我把sql语句打印出来,在查询分析器中能正确的显示
最有意思的是我在家试验好使,到公司就不好使了 !!郁闷啊 !!!