Help please....asp & vbscript


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Help please....asp & vbscript

  1. #1
    fugazi_8 opiate Guest

    Help please....asp & vbscript


    This is going to be longÖ


    I know vb and prefer to use vbscript on my asp pages.

    I have 2 tables mssql server(testing)

    Tables: topic and headlines

    topic columns:
    topicid, topics
    headline columns:
    headlineid, topicid, headline, headlinenews, startdate, endate

    my asp page is index.asp. my overall outcome is to be able to list by topic
    all the headlines in a html table format by todayís date where the topicid's
    match in each table.

    here is my select statement:
    sSQL = "SELECT TOPIC.TOPICID, TOPIC.TOPICS, HEADLINES.HEADLINEID, HEADLINES.HEADLINE
    FROM TOPIC INNER JOIN HEADLINES ON HEADLINES.TOPICID = TOPIC.TOPICID WHERE
    HEADLINES.STARTDATE = " & Chr(35) & Now() & Chr(35)

    it works fine! The problem Iím having is the vbscripting part. Iím trying
    to populate all the headlines from the headlines table by the topic in the
    topics table and only display the topic once like so...

    Topic1 Topic2
    ----------------------------------------------
    headline1 headline2
    headline1 headline2
    headline1 headline2

    Topic3 Topic4
    ----------------------------------------------
    headline3 headline4
    headline3 headline4
    headline3 headline4


    here is the code but itís not working it repeats the topic after every headline.

    <%
    while not rsnews.eof
    %>
    <table border=1><tr><td><%=rsnews("topics")%></td></tr>

    <tr><td><%=rsnews("headline")%></td></tr>
    <%
    rsnews.movenext
    wend
    %>
    </table>

    and the result is..

    Topic1
    heading1
    Topic1
    heading1
    Topic1
    heading1
    Topic2
    heading2
    Topic2
    heading2
    Topic2
    heading2

    and so on...

    I would be very greatfull to those who help me out.

    Thanks,

    Corey

  2. #2
    Michael Guest

    Re: Help please....asp & vbscript


    You can set a variable to hold the last topic and only display the topic line
    if it changes. You should do an ORDER BY TOPICS.TOPIC.

    Something like:

    lastTopic = ""
    Response.Write "<table>"
    While Not(rsnews.EOF)
    thisTopic = rsnews("topic")
    If lastTopic <> thisTopic Then
    Response.Write "<tr><td><br><br>" & thisTopic & "</td></tr>"
    End If
    Response.Write "<tr><td>" & rsnews("headline") & "</td></tr>"
    lastTopic = thisTopic
    Wend
    Response.Write "</table>"

    Good Luck!


    "fugazi_8" opiate wrote:
    >
    >This is going to be longÖ
    >
    >
    >I know vb and prefer to use vbscript on my asp pages.
    >
    >I have 2 tables mssql server(testing)
    >
    >Tables: topic and headlines
    >
    >topic columns:
    > topicid, topics
    >headline columns:
    > headlineid, topicid, headline, headlinenews, startdate, endate
    >
    >my asp page is index.asp. my overall outcome is to be able to list by topic
    >all the headlines in a html table format by todayís date where the topicid's
    >match in each table.
    >
    >here is my select statement:
    >sSQL = "SELECT TOPIC.TOPICID, TOPIC.TOPICS, HEADLINES.HEADLINEID, HEADLINES.HEADLINE
    >FROM TOPIC INNER JOIN HEADLINES ON HEADLINES.TOPICID = TOPIC.TOPICID WHERE
    >HEADLINES.STARTDATE = " & Chr(35) & Now() & Chr(35)
    >
    >it works fine! The problem Iím having is the vbscripting part. Iím trying
    >to populate all the headlines from the headlines table by the topic in the
    >topics table and only display the topic once like so...
    >
    >Topic1 Topic2
    >----------------------------------------------
    >headline1 headline2
    >headline1 headline2
    >headline1 headline2
    >
    >Topic3 Topic4
    >----------------------------------------------
    >headline3 headline4
    >headline3 headline4
    >headline3 headline4
    >
    >
    >here is the code but itís not working it repeats the topic after every headline.
    >
    ><%
    >while not rsnews.eof
    >%>
    ><table border=1><tr><td><%=rsnews("topics")%></td></tr>
    >
    ><tr><td><%=rsnews("headline")%></td></tr>
    ><%
    >rsnews.movenext
    >wend
    >%>
    ></table>
    >
    >and the result is..
    >
    >Topic1
    >heading1
    >Topic1
    >heading1
    >Topic1
    >heading1
    >Topic2
    >heading2
    >Topic2
    >heading2
    >Topic2
    >heading2
    >
    >and so on...
    >
    >I would be very greatfull to those who help me out.
    >
    >Thanks,
    >
    >Corey



  3. #3
    fugazi_8 Guest

    Re: Help please....asp & vbscript



    I can take it from here........thanks for the help!

    "Michael" <a2paw@hotmail.com> wrote:
    >
    >You can set a variable to hold the last topic and only display the topic

    line
    >if it changes. You should do an ORDER BY TOPICS.TOPIC.
    >
    >Something like:
    >
    >lastTopic = ""
    >Response.Write "<table>"
    >While Not(rsnews.EOF)
    > thisTopic = rsnews("topic")
    > If lastTopic <> thisTopic Then
    > Response.Write "<tr><td><br><br>" & thisTopic & "</td></tr>"
    > End If
    > Response.Write "<tr><td>" & rsnews("headline") & "</td></tr>"
    > lastTopic = thisTopic
    >Wend
    >Response.Write "</table>"
    >
    >Good Luck!
    >
    >
    >"fugazi_8" opiate wrote:
    >>
    >>This is going to be longÖ
    >>
    >>
    >>I know vb and prefer to use vbscript on my asp pages.
    >>
    >>I have 2 tables mssql server(testing)
    >>
    >>Tables: topic and headlines
    >>
    >>topic columns:
    >> topicid, topics
    >>headline columns:
    >> headlineid, topicid, headline, headlinenews, startdate, endate
    >>
    >>my asp page is index.asp. my overall outcome is to be able to list by

    topic
    >>all the headlines in a html table format by todayís date where the topicid's
    >>match in each table.
    >>
    >>here is my select statement:
    >>sSQL = "SELECT TOPIC.TOPICID, TOPIC.TOPICS, HEADLINES.HEADLINEID, HEADLINES.HEADLINE
    >>FROM TOPIC INNER JOIN HEADLINES ON HEADLINES.TOPICID = TOPIC.TOPICID WHERE
    >>HEADLINES.STARTDATE = " & Chr(35) & Now() & Chr(35)
    >>
    >>it works fine! The problem Iím having is the vbscripting part. Iím trying
    >>to populate all the headlines from the headlines table by the topic in

    the
    >>topics table and only display the topic once like so...
    >>
    >>Topic1 Topic2
    >>----------------------------------------------
    >>headline1 headline2
    >>headline1 headline2
    >>headline1 headline2
    >>
    >>Topic3 Topic4
    >>----------------------------------------------
    >>headline3 headline4
    >>headline3 headline4
    >>headline3 headline4
    >>
    >>
    >>here is the code but itís not working it repeats the topic after every

    headline.
    >>
    >><%
    >>while not rsnews.eof
    >>%>
    >><table border=1><tr><td><%=rsnews("topics")%></td></tr>
    >>
    >><tr><td><%=rsnews("headline")%></td></tr>
    >><%
    >>rsnews.movenext
    >>wend
    >>%>
    >></table>
    >>
    >>and the result is..
    >>
    >>Topic1
    >>heading1
    >>Topic1
    >>heading1
    >>Topic1
    >>heading1
    >>Topic2
    >>heading2
    >>Topic2
    >>heading2
    >>Topic2
    >>heading2
    >>
    >>and so on...
    >>
    >>I would be very greatfull to those who help me out.
    >>
    >>Thanks,
    >>
    >>Corey

    >



  4. #4
    Brandon Guest

    Re: Help please....asp & vbscript


    My code would look like this

    <table><tr><td colspan=4>Topics</td></tr>
    <tr>
    <%for x = 0 to rsnews.Fields.Count-1%>
    <td><%=rsnews.Fields.Item(x).Name%></td>
    <%rsnews.MoveNext%>
    <%next%>
    </tr>

    <%Do While Not rsnews.eof%>
    <tr><td><%=rsnews.fields("Topic1")%></td>
    <td><%=rsnews.fields("Topic2")%></td>
    <td><%=rsnews.fields("Topic3")%></td>
    <td><%=rsnews.fields("Topic4")%></td>
    </tr>
    <%rsnews.movenext%>
    <%loop%>
    </table>

    that should look like this

    Topic1 Topic2 Topic3 Topic4
    headline1 headline1 headline1 headline1
    headline2 headline2 headline2 headline2
    headline3 headline3 headline3 headline3








    "fugazi_8" opiate wrote:
    >
    >This is going to be longÖ
    >
    >
    >I know vb and prefer to use vbscript on my asp pages.
    >
    >I have 2 tables mssql server(testing)
    >
    >Tables: topic and headlines
    >
    >topic columns:
    > topicid, topics
    >headline columns:
    > headlineid, topicid, headline, headlinenews, startdate, endate
    >
    >my asp page is index.asp. my overall outcome is to be able to list by topic
    >all the headlines in a html table format by todayís date where the topicid's
    >match in each table.
    >
    >here is my select statement:
    >sSQL = "SELECT TOPIC.TOPICID, TOPIC.TOPICS, HEADLINES.HEADLINEID, HEADLINES.HEADLINE
    >FROM TOPIC INNER JOIN HEADLINES ON HEADLINES.TOPICID = TOPIC.TOPICID WHERE
    >HEADLINES.STARTDATE = " & Chr(35) & Now() & Chr(35)
    >
    >it works fine! The problem Iím having is the vbscripting part. Iím trying
    >to populate all the headlines from the headlines table by the topic in the
    >topics table and only display the topic once like so...
    >
    >Topic1 Topic2
    >----------------------------------------------
    >headline1 headline2
    >headline1 headline2
    >headline1 headline2
    >
    >Topic3 Topic4
    >----------------------------------------------
    >headline3 headline4
    >headline3 headline4
    >headline3 headline4
    >
    >
    >here is the code but itís not working it repeats the topic after every headline.
    >
    ><%
    >while not rsnews.eof
    >%>
    ><table border=1><tr><td><%=rsnews("topics")%></td></tr>
    >
    ><tr><td><%=rsnews("headline")%></td></tr>
    ><%
    >rsnews.movenext
    >wend
    >%>
    ></table>
    >
    >and the result is..
    >
    >Topic1
    >heading1
    >Topic1
    >heading1
    >Topic1
    >heading1
    >Topic2
    >heading2
    >Topic2
    >heading2
    >Topic2
    >heading2
    >
    >and so on...
    >
    >I would be very greatfull to those who help me out.
    >
    >Thanks,
    >
    >Corey



  5. #5
    Roger Guest

    Re: Help please....asp & vbscript


    Your problem is that you are writing the header out to the screen every time
    You could solve the problem like this:

    <%while not rsnews.eof
    If tmpID<><%=rsnews("topics")%> then%>
    <table border=1><tr><td><%=rsnews("topics")%></td></tr>
    <%End If%>
    <tr><td><%=rsnews("headline")%></td></tr>
    <%
    tmpID=<%=rsnews("topics")%>
    rsnews.movenext
    wend
    %>

    This code checks to see if you have already written the header out to the
    page. Hope this helps!

    "Brandon" <btyler@prodentec.com> wrote:
    >
    >My code would look like this
    >
    ><table><tr><td colspan=4>Topics</td></tr>
    ><tr>
    ><%for x = 0 to rsnews.Fields.Count-1%>
    > <td><%=rsnews.Fields.Item(x).Name%></td>
    > <%rsnews.MoveNext%>
    ><%next%>
    ></tr>
    >
    ><%Do While Not rsnews.eof%>
    ><tr><td><%=rsnews.fields("Topic1")%></td>
    > <td><%=rsnews.fields("Topic2")%></td>
    > <td><%=rsnews.fields("Topic3")%></td>
    > <td><%=rsnews.fields("Topic4")%></td>
    ></tr>
    ><%rsnews.movenext%>
    ><%loop%>
    ></table>
    >
    >that should look like this
    >
    >Topic1 Topic2 Topic3 Topic4
    >headline1 headline1 headline1 headline1
    >headline2 headline2 headline2 headline2
    >headline3 headline3 headline3 headline3
    >
    >
    >
    >
    >
    >
    >
    >
    >"fugazi_8" opiate wrote:
    >>
    >>This is going to be longÖ
    >>
    >>
    >>I know vb and prefer to use vbscript on my asp pages.
    >>
    >>I have 2 tables mssql server(testing)
    >>
    >>Tables: topic and headlines
    >>
    >>topic columns:
    >> topicid, topics
    >>headline columns:
    >> headlineid, topicid, headline, headlinenews, startdate, endate
    >>
    >>my asp page is index.asp. my overall outcome is to be able to list by

    topic
    >>all the headlines in a html table format by todayís date where the topicid's
    >>match in each table.
    >>
    >>here is my select statement:
    >>sSQL = "SELECT TOPIC.TOPICID, TOPIC.TOPICS, HEADLINES.HEADLINEID, HEADLINES.HEADLINE
    >>FROM TOPIC INNER JOIN HEADLINES ON HEADLINES.TOPICID = TOPIC.TOPICID WHERE
    >>HEADLINES.STARTDATE = " & Chr(35) & Now() & Chr(35)
    >>
    >>it works fine! The problem Iím having is the vbscripting part. Iím trying
    >>to populate all the headlines from the headlines table by the topic in

    the
    >>topics table and only display the topic once like so...
    >>
    >>Topic1 Topic2
    >>----------------------------------------------
    >>headline1 headline2
    >>headline1 headline2
    >>headline1 headline2
    >>
    >>Topic3 Topic4
    >>----------------------------------------------
    >>headline3 headline4
    >>headline3 headline4
    >>headline3 headline4
    >>
    >>
    >>here is the code but itís not working it repeats the topic after every

    headline.
    >>
    >><%
    >>while not rsnews.eof
    >>%>
    >><table border=1><tr><td><%=rsnews("topics")%></td></tr>
    >>
    >><tr><td><%=rsnews("headline")%></td></tr>
    >><%
    >>rsnews.movenext
    >>wend
    >>%>
    >></table>
    >>
    >>and the result is..
    >>
    >>Topic1
    >>heading1
    >>Topic1
    >>heading1
    >>Topic1
    >>heading1
    >>Topic2
    >>heading2
    >>Topic2
    >>heading2
    >>Topic2
    >>heading2
    >>
    >>and so on...
    >>
    >>I would be very greatfull to those who help me out.
    >>
    >>Thanks,
    >>
    >>Corey

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center