2013-01-11 42 views
0

我正在嘗試解決如何使頁面在url中無querystrings的情況下工作,默認頁面稱爲默認頁面。搜索頁面只有在url中存在查詢字符串時纔有效

實施例:

dbinstant.htm法律= &貓=所有== WORKS dbinstant.htm == ERROR如下

Microsoft OLE DB Provider for ODBC Drivers error '80040e14' 

[Microsoft][ODBC Text Driver] Syntax error (missing operator) in query expression '= 'Yes' AND ucase(legal) LIKE ucase('%%')'. 

/junk/dbinstant.htm, line 56 

PAGE CODE BELOW:

<%@ LANGUAGE="VBSCRIPT" %> 
<% 
pagetitle="Contractor Details" 
%> 
<!--#INCLUDE VIRTUAL="/_lib/include/header.htm"--> 
<!--#INCLUDE VIRTUAL="/_lib/include/menu.htm"--> 
<script> 
$(document).ready(function() { 
    $("#cat").change(function() { 
    this.form.submit(); 
}) 
$('#legal').focus() 
var typingTimer;     
var doneTypingInterval = 800; 

$('#legal').keyup(function(){ 
    clearTimeout(typingTimer); 
    if ($('#legal').val) { 
     typingTimer = setTimeout(doneTyping, doneTypingInterval); 
    } 
}); 

function doneTyping() { 
    $("form").submit(); 
} 

}); 
</script> 
<div class="twoColumnRow"> 
<div class="twoColumnContent"> 
<p class="breadCrm"><a href="/index.htm">Home</a> <span>&gt;</span> <a href="/tools/index.htm">Tools of the Trade</a> <span>&gt;</span> <a href="/tools/finance/index.htm">Finance and Purchasing</a><span>&gt;</span> <a href="/tools/finance/procurement/index.htm">Procurement and Contracts information</a></p> 
<div class="contentPad"> 
<!-- Start of main content --> 

<p class="imageRight">&nbsp;</p> 
<h1><%=pagetitle%></h1> 

<% 
     Dim connectString, connect, conDB, sconDB, lDB, con, scon, lcon, src_abn, src_cat 
     connectString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DBQ=" & Server.MapPath("data") 
       src_legal = Request.QueryString("legal") 
       src_cat = Request.QueryString("cat") 
     set connect = Server.CreateObject("ADODB.connection") 
     connect.open connectString 

     if src_cat = "all" then 
     conDB = "SELECT * FROM cont.csv WHERE ucase(legal) LIKE ucase('%"+src_legal+"%')" 
     lDB = "SELECT * FROM cont.csv WHERE ucase(legal) LIKE ucase('%"+src_legal+"%')" 
     else 
     conDB = " SELECT * FROM cont.csv WHERE " & src_cat & " = 'Yes' AND ucase(legal) LIKE ucase('%"+src_legal+"%')" 
     lDB = " SELECT * FROM cont.csv WHERE " & src_cat & " = 'Yes' AND ucase(legal) LIKE ucase('%"+src_legal+"%')" 
     end if 

     sconDB = "SELECT * FROM cont.csv" 

     set con = connect.execute(conDB) 
     set scon = connect.execute(sconDB) 
     set lcon = connect.execute(lDB) 
%> 
<h2>Search results</h2> 
<% if not con.BOF then %> 
<div style="margin-top:1em"> 

    <form id="searchf" action="dbinstant.htm" method="get"> 

     <p>Company name:1<br/> 
     <input id="legal" name="legal" type="text" value="<%=src_legal%>"> 
     </p> 
    <p>Categories for Creative Design:<br/> 
     <select id="cat" name="cat"> 
     <option class="group" label="All categories" value="all" <%if request.querystring("cat") = "all" then response.write("selected") %>></option> 
     <option class="group" label="Strategic brand, marketing and communications advice" value="a" <%if request.querystring("cat") = "a" then response.write("selected") %>></option> 
     <option class="group" label="Graphic design and layout" value="b" <%if request.querystring("cat") = "b" then response.write("selected") %>></option> 
     <option class="group" label="Forms design" value="c" <%if request.querystring("cat") = "c" then response.write("selected") %>></option> 
     <option class="group" label="Web design and development" value="d" <%if request.querystring("cat") = "d" then response.write("selected") %>></option> 
     <option class="group" label="Authoring services" value="e" <%if request.querystring("cat") = "e" then response.write("selected") %>></option> 
     <option class="group" label="Editorial services" value="f" <%if request.querystring("cat") = "f" then response.write("selected") %>></option> 
     <option class="group" label="Translation services" value="g" <%if request.querystring("cat") = "g" then response.write("selected") %>></option> 
     <option class="group" label="Photography and film services" value="h" <%if request.querystring("cat") = "h" then response.write("selected") %>></option> 
     <option class="group" label="Scanning and digitisation services" value="i" <%if request.querystring("cat") = "i" then response.write("selected") %>></option> 
     <option class="group" label="Multimedia editing services" value="j" <%if request.querystring("cat") = "j" then response.write("selected") %>></option> 
     </select> 
    </p> 
    <input type="submit" value="Search" /> 
    </form> 
    <br /> 

    <table style="font-size:.9em;" class="contentTable"> 
      <tr> 
       <th>ABN:</th> 
       <th>Company Name:</td> 
      </tr> 
    <% con.Movefirst() %> 
    <% while (NOT con.EOF) %> 
      <tr> 
       <td width="120px"><%=con("abn")%></th> 
       <td><a href="dbcomp.htm?abn=<%=con("abn")%>&cat=all"><%=con("legal")%></a></td> 
      </tr> 
    <% 
    con.MoveNext() 
    Wend 
    %> 
</table> 

</div> 
<% else %> 
    <% scon.Movefirst() %> 
    <form action="dbinstant.htm" method="get"> 

     <p>Company name:2<br/> 
     <input id="legal" name="legal" type="text"> 
     </p> 

    <p>Categories for Creative Design:<br/> 
     <select id="cat" name="cat"> 
     <option class="group" label="All categories" value="all" <%if request.querystring("cat") = "all" then response.write("selected") %>></option> 
     <option class="group" label="Strategic brand, marketing and communications advice" value="a" <%if request.querystring("cat") = "a" then response.write("selected") %>></option> 
     <option class="group" label="Graphic design and layout" value="b" <%if request.querystring("cat") = "b" then response.write("selected") %>></option> 
     <option class="group" label="Forms design" value="c" <%if request.querystring("cat") = "c" then response.write("selected") %>></option> 
     <option class="group" label="Web design and development" value="d" <%if request.querystring("cat") = "d" then response.write("selected") %>></option> 
     <option class="group" label="Authoring services" value="e" <%if request.querystring("cat") = "e" then response.write("selected") %>></option> 
     <option class="group" label="Editorial services" value="f" <%if request.querystring("cat") = "f" then response.write("selected") %>></option> 
     <option class="group" label="Translation services" value="g" <%if request.querystring("cat") = "g" then response.write("selected") %>></option> 
     <option class="group" label="Photography and film services" value="h" <%if request.querystring("cat") = "h" then response.write("selected") %>></option> 
     <option class="group" label="Scanning and digitisation services" value="i" <%if request.querystring("cat") = "i" then response.write("selected") %>></option> 
     <option class="group" label="Multimedia editing services" value="j" <%if request.querystring("cat") = "j" then response.write("selected") %>></option> 
     </select> 
    </p> 
    <input type="submit" value="Search" /> 
    </form> 
    <br /><hr /> 
<p>No records match your query.</p> 
<p><a href="dbtest.htm">Return to search page</a></p> 
<% 
    end if 
    con.close 
%> 


<!-- End of main content --> 
</div> <!-- end contentPad div --> 
</div> <!-- end twocolumncontent div --> 
<div class="twoColumnLinks"> 

<!--<div class="relatedLinks"> 
<h3>Related Links</h3> 
<ul> 
<li><a href="/index.htm">Related link 1</a></li> 
</ul> 
</div>--> <!-- end relatedlinks div --> 
<!--#INCLUDE VIRTUAL="/_lib/include/quicklinks.htm"--> 
<!--#INCLUDE VIRTUAL="/_lib/include/mylinks.htm"--> 
</div> <!-- end twocolumnlinks div --> 
</div> <!-- end twocolumnrow div --> 
<!--#INCLUDE VIRTUAL="/_lib/include/footer.htm"--> 
+0

這只是一個代碼轉儲。如果您將代碼縮小到顯示問題的最小值,並詢問具體問題,您會得到更好的迴應。 –

回答

1

如果你想從你的查詢字符串中刪除額外的字段,我想你只想將你的表單操作標籤改爲POST,然後更改所有實例o ˚F

Request.QueryString("variable") 

Request.Form("variable") 

甚至只是

Request("variable") 

--edit

因此,看來你只想做這樣的事情:

if src_cat = "" then 
    conDB = "SELECT * FROM cont.csv WHERE 1=2" 
    lDB = "SELECT * FROM cont.csv WHERE 1=2" 
elseif src_cat = "all" then 
    conDB = "SELECT * FROM cont.csv WHERE ucase(legal) LIKE ucase('%"+src_legal+"%')" 
    lDB = "SELECT * FROM cont.csv WHERE ucase(legal) LIKE ucase('%"+src_legal+"%')" 
else 
    conDB = " SELECT * FROM cont.csv WHERE " & src_cat & " = 'Yes' AND ucase(legal) LIKE ucase('%"+src_legal+"%')" 
    lDB = " SELECT * FROM cont.csv WHERE " & src_cat & " = 'Yes' AND ucase(legal) LIKE ucase('%"+src_legal+"%')" 
end if 

如果src_cat爲空,則需要確定是否要顯示所有內容,沒有內容或其他內容。在上面的示例中,WHERE子句中的setting 1=2確保這兩個sql字符串不顯示任何內容。

+0

我希望能夠訪問dbinstant.htm(併爲它顯示一個默認頁面),但彈出錯誤,因爲它找不到查詢字符串 – sephiith

+0

@sephiith請參閱上面的編輯 - 祝你好運。 – sgeddes

+0

這正是我想要的。你是個天才! – sephiith

相關問題