help with a query output

  • If anyone can help it would be great. Im new to SQL and point in the right direction would be great.

    Here is my code.

    <!--#include file="s4r.asp" -->

    <%

    var to = Server.CreateObject("ADODB.Recordset");

    to.ActiveConnection = MM_s4r_STRING;

    to.Source = "SELECT newdate, news FROM dbo.news";

    to.CursorType = 0;

    to.CursorLocation = 2;

    to.LockType = 1;

    to.Open();

    var to_numRows = 0;

    %>

    <---this is what i need help with. -->

    <%= Server.URLEncode((to.Fields.Item("news").Value)) %>

    <%= Server.URLEncode((to.Fields.Item("newdate").Value)) %>

    <%

    to.Close();

    %>

    This is the result:

    A+PBX+%28

    private+branch+exchange%29+is+a+telephone+system+within+an+enterprise+that+switches+calls+between+enterprise+users+on+local+lines+while+allowing+all+users+to+share+a+certain+number+of+external+phone+lines%2E+The+main+purpose+02%2E05%2E05

    How do add a write function to this part of the code.

    <%= Server.URLEncode((to.Fields.Item("news").Value)) %>

    <%= Server.URLEncode((to.Fields.Item("newdate").Value)) %>

    to make the result display in a format like this

    &news=2E05%2E05

    &newdate=telephone+system+within+an+enterprise+that+switches+calls+between+enterprise+users+on+local+lines+while+allowing+all+users+to+share+a+certain+number+of+external+phone+lines%2E+The+main+purpose+02%2E05%2E05

    I have tried some doc.write functions but doesnt work... any help would be great thanks.

     

     

  • document.write is client side stuff.

    Response.Write is server side.

    <%= is short hand for Response.Write

    Response.Write "&news=" + Server.URLEncode((to.Fields.Item("news").Value))

  • I think it should be

    Response.Write "&news=" & Server.URLEncode(to.Fields.Item("news").Value)

    Bert

  • Hi Bert,

    As everyone has pointed out, you would use server.urlencode, if you need

    to pass values, which has characters that are usually part of a query string.

    On the other hand, you would use server.htmlencode, if you need to display

    html tags as part of your text, on the web page.

    Hope this helps..

    Cheers,

    Sai

  • Thanks for the feedback. I tried this...

    -------------------------------------------

    <%

    var to = Server.CreateObject("ADODB.Recordset");

    to.ActiveConnection = MM_s4r_STRING;

    to.Source = "SELECT newdate, news FROM dbo.news";

    to.CursorType = 0;

    to.CursorLocation = 2;

    to.LockType = 1;

    to.Open();

    var to_numRows = 0;

    %>

    <%= Response.Write "&news=" & Server.URLEncode((to.Fields.Item("news").Value)) %>

    <%= Server.URLEncode((to.Fields.Item("newdate").Value)) %>

    <%

    to.Close();

    %>

    ________________________________________--

    Response was 500 error.

    Microsoft JScript compilation error '800a03ee'

    Expected ')'

    /stage1/_inc/news2.asp, line 14

    Response.Write(Response.Write "&news=" & Server.URLEncode((to.Fields.Item("news").Value)))------------------------------^

    any ideas?

     

    line 14 : <%= Response.Write "&news=" & Server.URLEncode((to.Fields.Item("news").Value)) %>

    I did add another ) but again gave a 500

  • <%

    var to = Server.CreateObject("ADODB.Recordset");

    to.ActiveConnection = MM_s4r_STRING;

    to.Source = "SELECT newdate, news FROM dbo.news";

    to.CursorType = 0;

    to.CursorLocation = 2;

    to.LockType = 1;

    to.Open();

    var to_numRows = 0;

    %>

    <%

    Response.Write "&news=" & Server.URLEncode(to.Fields.Item("news").Value)

    Response.Write Server.URLEncode(to.Fields.Item("newdate").Value)

    %>

    <%

    to.Close();

    %>

  • Thanks for the reply... This is still giving a 500

    <%

    var to = Server.CreateObject("ADODB.Recordset");

    to.ActiveConnection = MM_s4r_STRING;

    to.Source = "SELECT newdate, news FROM dbo.news";

    to.CursorType = 0;

    to.CursorLocation = 2;

    to.LockType = 1;

    to.Open();

    var to_numRows = 0;

    %>

    <%

    Response.Write "&news=" & Server.URLEncode(to.Fields.Item("news").Value)

    Response.Write "&newdate=" & Server.URLEncode(to.Fields.Item("newdate").Value)

    %>

    <%

    to.Close();

    %>

     

    No visual error but server logs state - 800a03ec|Expected_';'

  • VBScript

    Response.Write "&news=" & Server...

    JavaScript

    Response.Write "&news=" + Server...

    If you are using Visual Studio to write your code there is a way of setting up line by line debugging however I have come closer to solving Fermat's last theorem than getting it to work.

  • My mistake ... I  did not see it was javascript ... Try this :

    <%

    var to = Server.CreateObject("ADODB.Recordset");

    to.ActiveConnection = MM_s4r_STRING;

    to.Source = "SELECT newdate, news FROM dbo.news";

    to.CursorType = 0;

    to.CursorLocation = 2;

    to.LockType = 1;

    to.Open();

    var to_numRows = 0;

    %>

    <%

    Response.Write("&news=" + Server.URLEncode(to.Fields.Item("news").Value));

    Response.Write("&newdate=" + Server.URLEncode(to.Fields.Item("newdate").Value));

    %>

    <%

    to.Close();

    %>

  • Welll i think its getting there...

     

    -------------------------------------

    <%@LANGUAGE="JAVASCRIPT"%>

    <!--#include file="s4r.asp" -->

    <%

    var go = Server.CreateObject("ADODB.Recordset");

    go.ActiveConnection = MM_s4r_STRING;

    go.Source = "SELECT newdate, news FROM dbo.news";

    go.CursorType = 0;

    go.CursorLocation = 2;

    go.LockType = 1;

    go.Open();

    var go_numRows = 0;

    %>

    <% Response.Write "&news=" + (go.Fields.Item("news").Value)%>

    <% Response.Write "&newdate=" + (go.Fields.Item("newdate").Value)%>

    <%

    go.Close();

    %>

    ----------------------------

    500 error - 

    Microsoft JScript compilation error '800a03ec'

    Expected ';'

    /stage1/_inc/news2.asp, line 14

    Response.Write "&news=" + (go.Fields.Item("news").Value)
    ---------------^
     looks like there is suppose to be a ; right before the " ???

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply