Page 1 of 2 12 LastLast
Results 1 to 15 of 28

Thread: ASP question

  1. #1
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP question

    I hoping to somehow create a FAQ section for my website. At the moment, I'm displaying the question and then the answer, and so on and so on. So for example, my output looks like this...
    Q ....
    A ...
    Q...
    A...

    What I'm hoping to do is somehow group the questions and link to them within the document using anchor tags to the correct corresponding answer. So I need to group the answers down below as well. Any clue how I can accomplish this. Here is my code up to this point. At the moment, I'm not pulling the ID from the db, but each question/answer has a uniqued ID....

    <%
    Set Recordset1 = Server.CreateObject("ADODB.Recordset")
    Recordset1.ActiveConnection = MM_connectDB_STRING
    Recordset1.Source = "SELECT faqDate, Question, Answer FROM tbl_FAQ where FAQ = 1"
    Recordset1.CursorType = 0
    Recordset1.CursorLocation = 2
    Recordset1.LockType = 1
    Recordset1.Open()
    Recordset1_numRows = 0
    Repeat1__numRows = -1
    Repeat1__index = 0
    Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
    %>
    FAQ (Frequently Asked Questions)


    If your can't find an answer, please submit your question through the "Ask a Question" section below.



    <table>
    <%
    Do While NOT Recordset1.EOF
    %>
    <tr>
    <td><%=(Recordset1.Fields.Item("Question").Value)% ></td>
    </tr>
    <tr>
    <td><%=(Recordset1.Fields.Item("Answer").Value)% ></td>
    </tr>
    <%
    Recordset1.MoveNext
    Loop
    %>
    </table>
    <%

    Thanks beforehand!!!!

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    Hi Muscle (I used to be mostly muscle, but not anymore... <img src=/S/smile.gif border=0 alt=smile width=15 height=15>)

    You're definitely on the right track. WIth just a few tweaks, you'll be in business.

    To add an anchor to the corresponding answer, I would suggest using each answer's ID, as you mentioned.

    Simply use the following ASP for your answer item (note that you can also refer to a field's value with Recordset1("Fieldname") - it's just easier to type that way)
    ...<td><a name="<%=Recordset1("AnswerID")%>"><%=Recordset1(" Answer")%></a></td>...

    Also, be sure to add the correct field to your Recordset.Source line (I used "AnswerID", but replace that with your ID field's name).

    Do you also have a section of the page that has the Questions with links to the corresponding answer?
    If so, you could set it up like this:

    <% Do Until Recordset1.EOF
    Response.Write("<a href=#""" & Recordset1("AnswerID") & ">" & Recordset1("Question") & "</a>")
    Recordset1.MoveNext
    Loop
    %>

    Hope this helps - please post back if you have any more questions (or answers <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>)

  3. #3
    KTYorke
    Guest

    Re: ASP question

    Well, I don't have an ASP answer for you... but I did just come up with a FAQ page using JavaScript from the JavaScript Source. The code is attached.
    I've used it on the FAQ page for my college class site. To see how it works and if it's what you're after, see: http://www.mmcclassof98.com/faq.html
    have fun

  4. #4
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    Thanks so much for the prompt response Mark. I'm new to ASP(ColdFusion Junkie) so try to bear with me <img src=/S/doh.gif border=0 alt=doh width=15 height=15> . I have the following table structure(fields) in my Access DB...
    ID, Answer, Question, and FAQ. ID is the generated number, Answer and Question are of course self explanatory, and FAQ is if it is included in the FAQ section. What I'm hoping to accomplish is...

    I'm hoping to display all my questions first and hopefully numbered like 1. 2. 3. etc. If you know how to do that, It would be greatly appreciated. I can display them, just cant get a number to display next to them. Second I want to have each as a link to the specific answer which will be further down the page in a group of answers. At the moment, I'm displaying the question and then the answer right after it. But I think this model would be much better. Either way, thanks again soo much for helping.

    Code right now...

    <%
    Set Recordset1 = Server.CreateObject("ADODB.Recordset")
    Recordset1.ActiveConnection = MM_connectDB_STRING
    Recordset1.Source = "SELECT ID, faqDate, Question, Answer FROM tbl_FAQ where FAQ = 1"
    Recordset1.CursorType = 0
    Recordset1.CursorLocation = 2
    Recordset1.LockType = 1
    Recordset1.Open()
    Recordset1_numRows = 0
    Repeat1__numRows = -1
    Repeat1__index = 0
    Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
    %>
    <table>
    <%
    Do While NOT Recordset1.EOF
    %>
    <tr>
    <td>[b]<%=(Recordset1.Fields.Item("Question").Value)%></td>
    </tr>
    <tr>
    <td><%=(Recordset1.Fields.Item("Answer").Value)% ></td>
    </tr>
    <%
    Recordset1.MoveNext
    Loop
    %>
    </table>
    <%
    Recordset1.Close()
    Set Recordset1 = Nothing
    %>

  5. #5
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    OK - that helps me have a better idea of your needs... I would suggest adding another field in your table for Question number (since the Auto generated ID field may possibly skip numbers). Then number these sequentially as needed - If you use the HTML [list=1] tag (ordered list), the question and answer numbers may possibly change from time to time. It will give you more control over the numbers if you create them yourself. (I added "ORDER BY faqNumber" to your SQL so it would sort by the new faqNumber field.)

    This may be a bit of a long post with the code, but bear with me. I'll comment in the code as needed. Also, I'll use more of the Response.Write method because it's a little more efficient than bouncing in and out of script (<%..%>) tags.

    (Note that I used < br > to separate the questions and answers. You may choose to use a table as you did in the code you posted. Simply change the tags and you'll be fine - be careful of the script syntax, though.)<pre>'Your connection code (with the addition of a new field - faqNumber
    Set Recordset1 = Server.CreateObject("ADODB.Recordset")
    Recordset1.ActiveConnection = MM_connectDB_STRING
    Recordset1.Source = "SELECT ID, faqDate, faqNumber, Question, Answer " _
    & "FROM tbl_FAQ where FAQ = 1 ORDER BY faqNumber"
    Recordset1.CursorType = 0
    Recordset1.CursorLocation = 2
    Recordset1.LockType = 1
    Recordset1.Open()
    Recordset1_numRows = 0
    Repeat1__numRows = -1
    Repeat1__index = 0
    Recordset1_numRows = Recordset1_numRows + Repeat1__numRows

    'Write the Question list with links to the Answer Anchors and the new faqNumber field as numbers
    Response.Write("FAQ - Questions:")
    Recordset1.MoveFirst
    Do Until Recordset1.EOF
    Response.Write("<a href=""#faq" & Recordset1("ID") & """>" & Recordset1("faqNumber") & ".

  6. #6
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    You're going to kill me. I've been told I can't touch the database. So it's not a problem to leave out the ordering. So basically I'm just going to display the group of questions and then the group of answers below it. Of course with anchor tags, which you have generously already provided. I've set up your initial code w/o the questions becuase I get an error. It's like I need to do somekind of different loop. Here is what I have which is almost complete... Thanks again for everything. It;s people like you that make learning so enjoyable. Thanks Again!!!


    <%
    Set Recordset1 = Server.CreateObject("ADODB.Recordset")
    Recordset1.ActiveConnection = MM_connectDB_STRING
    Recordset1.Source = "SELECT ID, faqDate, Question, Answer FROM tbl_FAQ where FAQ = 1"
    Recordset1.CursorType = 0
    Recordset1.CursorLocation = 2
    Recordset1.LockType = 1
    Recordset1.Open()
    Recordset1_numRows = 0
    Repeat1__numRows = -1
    Repeat1__index = 0
    Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
    %>
    <table>
    <% Do While NOT Recordset1.EOF %>
    <tr>
    <td><a name="<%=Recordset1("ID")%>"><font size="-2"><%=Recordset1("Answer")%></font></a>

    </td>
    </tr>
    <% Recordset1.MoveNext
    Loop %>
    </table>

    <%
    Recordset1.Close()
    Set Recordset1 = Nothing
    %>

  7. #7
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    Sorry for the delay - I was out at meetings all afternoon...

    Ok - no need to worry about the database. Why don't you use the [list=1] (Ordered List) tag. That will give the user a way to see a number. Since there's an answer for every question, the numbering will match without any problem. Whether or not you use a table is up to you - you don't really need one if you use the OL tag...

    I'm not sure why the code I posted crashed - it's hard to tell without seeing your entire page and database setup.

    I'll try again. Questions:
    <img src=/w3timages/blackline.gif width=33% height=2>
    1. <%
      Recordset1.MoveFirst
      Do Until Recordset1.EOF
      '(actually works the same as Do While NOT Recordset1.EOF) %>
    2. "><%=Recordset1("Question")%>
      <% Recordset1.MoveNext
      Loop %>

    ....

    Answers:
    <img src=/w3timages/redline.gif width=33% height=2>
    1. <% Recordset1.MoveFirst
      Do Until Recordset1.EOF %>
    2. <a name="faq<%=Recordset1("ID")%>"><%=Recordset1("Ans wer")%></a>
      <% Recordset1.MoveNext
      Loop %>


    Give that a shot... If you get an error, please post it with the line that's causing the problem.

    Keep us posted!

  8. #8
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    Mark:

    Can't thank you enough. The last code you so generously posted worked beautifully!! Again, thanks for everything, and if you ever have a question about ColdFusion, please let me know.

    Thanks Again!!!

  9. #9
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    I'm glad to hear that it worked! I imagine it's a big change to move from ColdFusion to ASP... but it seems like you're on the right track.

    Have you worked with ColdFusion MX? I have the "Personal" edition that comes with StudioMX, but I haven't taken the time to play with it - mainly because all of the web hosts I work with only have CF 5.

    I'm anxious to have the opportunity to consume Web Services with CF MX. I've played with it a bit on my copy and it's REALLY powerful. I haven't tried doing the same with ASP.NEtT, so I'll be curious to see how easy it is there.

    Have a great day!

  10. #10
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    Hey MarkJ:

    To answer your question, I was a big ColdFusion 4.5 fan and have just now started working with MX. Unfortunately, I have not used it enough to form an opinion, but will elt you know when I do.

    I was hoping to ask you a question if you had some time? Do you know of a script that tests to see if the Flash Player and if Windows Media Player is installed. I need to test in my ASP page to see if they're installed, and if so provide the relative links. So for example, if Flashis installed, display the flash file, and if WMP is installed, display the WMP file, and if both are installed, display both files. I hope I'm clear enough. I figured you would be the pro to ask. Thanks again!!!

  11. #11
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    Hi Muscle,

    FlashMX will automatically generate the HTML/JavaScript to detect for the selected version when you publish your SWF file (File | Publish).

    If you don't have access to this software, you can check a couple of my websites for a good example (both are located on the opening page). Both of these check for version 5 of Flash Player (my choice), and show alternate content if it's not present (in this case, a JPG):
    http://JTimms.com
    http://MeridianSongProject.org

    (Based on your previous posts, I'll assume that you are comfortable digging through HTML and JavaScript to find the necessary info you need. If, however, you need more specific help please let me know.)

    As for detecting WMP, I've never tried it, but I imagine the JavaScript is very similar to the Flash detection process. The only difference is that you're checking for WMP instead of Flash. I'll bet Microsoft has some code samples on their website that will demonstrate this. I'll see if I can locate anything like that.

    In the meantime, I hope this helps! <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  12. #12
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    Thanks so much for the prompt reply Mark. By the way, you can call me Nick) (FYI, I love to spend all of my free time in the gym, so that's where muscle comes from). Anyway, I've been able to write a script that checks for both the Windows Media Player and Flash Player. Here is my problem now. I have an ASP page in which I'm displaying media files that deal with that specific text (page). I've created an additional function in my global.asp page like so...

    <% function Detect(myDepth) %>
    <script language="JavaScript">
    var agt=navigator.userAgent.toLowerCase();
    var ie = (agt.indexOf("msie") != -1);
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
    var mac = (agt.indexOf("mac")!=-1);

    if (ie && win) { pluginlist = detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockw ave Flash") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player"); }
    if (ns || !win) {
    nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
    pluginlist = detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("application/x-mplayer2","Windows Media Player");
    }

    function detectIE(ClassID,name) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>n on error resume next n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>n'); if (result) return name+','; else return ''; }
    function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }

    pluginlist += navigator.javaEnabled() ? "Java," : "";
    if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);
    </script>
    <% end function %>

    What I'm hoping to do now is somehow call this function in my page, and write some kind of ASP code to check for each player and if detected display the link or image.

    So for example, if a user has WMP but no flash, I'd like to only display the Windows Media Player link/image. Is this possible? Again, thanks so much for everything.

  13. #13
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    Hi Nick,

    You mentioned including this function in your "global.asp" page - do you mean "global.asa"?

    I'm not clear on what's not working... It could be that the Lounge is improperly displaying all of your code - try placing it inside the [ pre ] ... [ / pre ] tags... That allows you to post properly formatted code without the lounge mistaking a [ i ] for italics.

    I'm not sure how you're referencing this function. I would suggest a similar approach, except with an Include directive and a JavaScript function name instead of Server-side function name:

    < ! - - #INCLUDE FILE="detect.inc" - - >

    <img src=/w3timages/blackline.gif width=33% height=2>
    (detect.inc below)
    <script language="JavaScript">
    function detect() {
    //Insert your code here
    }
    </script>
    <img src=/w3timages/blackline.gif width=33% height=2>

    Then call your function to detect totally on the client side. Was the ASP stuff part of THIS process, or was it for other things on the page?

    Hope this helps...

  14. #14
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    OK, I think I'm all messed up) Let me try to do a better job of explaining because I have myself confused, lol. I've got a page called contents.asp which is called into the main page to display the pertinent information like so...

    contents.asp
    [ pre ]
    <% function content(whatPage) %>
    <% if whatPage = "sec_01_001" OR whatPage = "ALL" then %>
    <%
    getMedia = "SELECT id, title, description FROM media WHERE id=1"
    set SQL = cnnSimple.execute(getMedia)
    %>
    <table cellspacing="0" cellpadding="2" width="100%">
    <tr>
    <td valign="top" width="99%">
    <A href="java scriptpenWindow('<%=myDepth%>m/01/001.asp', 'media', 'width=600,height=400,scrollbars=no')">
    <%=SQL("title")%></a> (Windows Media Sample)
    <%=SQL("description")%>
    </td>
    </tr>
    </table>


    <table cellspacing="0" cellpadding="2" width="100%">
    <tr>
    <td valign="top" width="99%">
    <A href="java scriptpenWindow('<%=myDepth%>m/01/111.asp', 'media', 'width=550,height=338,scrollbars=no')">
    <%=SQL("title")%></a> (Flash Sample)
    <%=SQL("description")%>
    </td>
    </tr>
    </table>


    <table cellspacing="0" cellpadding="2" width="100%">
    <tr>
    <td valign="top" width="99%">
    <A href="java scriptpenWindow('<%=myDepth%>m/01/201.asp', 'media', 'width=600,height=400,scrollbars=no')">
    <%=SQL("title")%></a> (HTML Sample)
    <%=SQL("description")%>
    </td>
    </tr>
    </table>
    <% exit function %>
    <% end if %>
    [ / pre ]

    I thought what a luxury it would be to the user if I could only display the specific links for the players they have installed and leave the others transparent. So if the user has no Flash, he/she wouldn't be able to view the Flash link. Now the HTML link would always be displayed. I have a javascript which detects whether or not the players are displayed, I'm just not sure how to implement it in my code. I apologize about the global.asa file. I was totally wrong. I need to somehow include this into the contents.asp file. Here is the javascript code that is working beautifully...

    [ pre ]
    <script language=JavaScript>
    <!--
    var agt=navigator.userAgent.toLowerCase();
    var ie = (agt.indexOf("msie") != -1);
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
    var mac = (agt.indexOf("mac")!=-1);

    if (ie && win) { pluginlist = detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockw ave Flash") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player"); }
    if (ns || !win) {
    nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
    pluginlist = detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("application/x-mplayer2","Windows Media Player");
    }

    function detectIE(ClassID,name) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>n on error resume next n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>n'); if (result) return name+','; else return ''; }
    function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }

    pluginlist += navigator.javaEnabled() ? "Java," : "";
    if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);
    </script>
    [ / pre ]

  15. #15
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP question

    Hi Nick,

    I should have explained - I intentionally left spaces in the [ pre ] tags so they wouldn't be picked up. Try again without the spaces... I included a lot of HTML code and forgot the pre tags - anything that was a comment (< ! - -.... - - >) was left out of the post... Needless to say, I learned the hard way. <img src=/S/stupidme.gif border=0 alt=stupidme width=30 height=30>

    Even without the help of the formatting, I think I understand the problem. Detecting the plugins happens totally on the Client side. Therefore, you'll need JavaScript to detect whether they have the appropriate plugins and decide whether or not to show the links - assuming this all happens on ONE page. Alternatively, you could detect the plugins on one page, send a form variable back to the server, then determine which links to show on following pages. Does that make sense?

    The logic for scenario 1 would be: (all JavaScript)
    1) Detect Plugin
    2) If Plugin = True, show link
    3) else (Plugin = False), don't show link

    The logic for scenario 2 would be: (JavaScript + ASP)
    1) Page 1 - Detect Plugin, set Form variable to Plugin Status (perhaps true/false)
    2) Page 2 - If Request.Form(PluginStatus) = True, Generate link
    3)... Else (Request.Form(PluginStatus) = False), don't generate link


    I hope that helps... If not, post back. We'll keep it rolling until you get it right! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Page 1 of 2 12 LastLast

Posting Permissions

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