Results 1 to 4 of 4

Thread: Spaces,Spaces,Spaces

  1. #1
    hairless Guest

    Default Spaces,Spaces,Spaces

    I&#039ve searched high and low for an answer to this without success. Please somebody help.<BR><BR>I&#039ve created a form which reads all the records from a database table (not one of mine), whose field names unavoidably contain spaces (Contact Name, Enquiry Date, etc.). I&#039ve made the column headings into links which are meant to sort the columns into ascending order with the code below (abbreviated).<BR><BR>dim strSort<BR>if request.queryString="" then<BR>strSort="Company"<BR>else<BR>strSort=reque st.queryString("sort")<BR><BR>Dim SQL<BR>SQL="Select * from myTable ORDER BY &#039"&strSort&"&#039"<BR><BR>I&#039ve then constructed my link like this:<BR>&#060;a href="target.asp?sort=&#060;%=rs(i).Name%&#062;"&# 062;&#060;%=rs(i).Name%&#062;&#060;/a&#062;<BR><BR>This is fine until rs(i).Name contains a space. I&#039ve tried using square brackets [] and server.urlEncode() and replace() in every conceivable place and in every possible combination, but while IE5.5 tolerates it well, NN4.7 refuses to have any of it.<BR><BR>What is the established method for solving this, PLEASE?

  2. #2
    Mauricio C. Guest

    Default Have u tried %20?

    Replace(String," ","%20")<BR><BR>it werks for me.

  3. #3
    Join Date
    Dec 1969

    Default RE: Spaces,Spaces,Spaces

    A couple of bugs in that...Herewith my revisions...comments below:<BR><BR>&#060;%<BR>dim strSort<BR>If request.queryString("sort") = "" then &#039 COMMENT 1<BR> &nbsp; strSort="Company"<BR>else<BR> &nbsp; strSort=request.queryString("sort")<BR>End If &#039 missed this !<BR><BR>Dim SQL<BR>SQL="Select * from myTable ORDER BY [" & strSort & "]" &#039 COMMENT 2<BR>%&#062;<BR><BR>********** <BR>COMMENT 3 PERTAINS TO PRIOR PAGE:<BR><BR>&#060;a href="target.asp?sort=&#060;%= Server.URLEncode(rs(i).Name) %&#062;"&#062;<BR>&#060;%=rs(i).Name%&#062;<BR>&#0 60;/a&#062;<BR><BR>*********************************** *****<BR><BR>(1) Not truly a bug, but suppose somebody passed x=123 as the querystring? You&#039d see that the querystring *DID* have a value and then try to get the sort order and get nothing. Kablooey! A bad SQL query.<BR><BR>(2) You were putting &#039...&#039 around the name of the field! NO! That would cause it to try to sort on a constant. If it didn&#039t produce a SQL error, I dunno what it would do. But it wouldn&#039t do what you want! You must put [...] around field names that use reserved SQL keywords or, as you noted, contain spaces.<BR><BR>(3) I don&#039t know what you were doing wrong with Server.URLEncode, but the form I show is the right way. You want to *only* encode the *value* of the thing being passed, never the name or the equals sign (trying to guess what mistake you made when you tried it).<BR><BR>If the above doesn&#039t work, please let me know, with what happens. Okay to email:<BR><BR>

  4. #4
    hairless Guest

    Default RE: Spaces,Spaces,Spaces

    Thank you Bill.<BR><BR>It was the ORDER BY ["&strSort&"] which solved the problem. Where did I get the idea that you always needed to put quotes round an *ORDER BY* value?<BR>Now that I&#039ve combined your line with Server.UrlEncode(), Netscape is happy again. Me too! Cheers!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts