Author |
Topic |
erico
Starting Member
34 Posts |
Posted - 2007-04-20 : 14:17:04
|
I'm so very close on this but I sure could use some help with it. I have an asp page that displays story content and just below that names, descriptions and URL's as text links. The story content displays just fine but the guestnames and URL's always show only one record and it's always the same record. Meaning same name every time I test. I have three tables being referenced in my sql code. They are:T_ProgramsT_ProgramGuestsT_ProgramLinksI'm also referencing them by id and yes I know about sql injections but for now I have to get this to work right. Security will be later. Below is only the code you need not the entire asp page.<!-- BEGINNING OF THE GUESTS AND LINKS SECTION --><% set con = Server.CreateObject("ADODB.Connection") con.Open "File Name=E:\webservice\Company\Company.UDL" set rs = Server.CreateObject("ADODB.Recordset")id=request.querystring("id") 'If this line is commented out the page will be blank. 'However you can still append a record number to the end of the URL and display that one.IF id <> "" then id=id else id="9726" end if 'This line shows the default record of 9726. 'If this line is commented out the page will ONLY 'show the default record but will NOT allow you to 'append a different number.strSQL = "SELECT *, T_Programs.ID AS Expr1, T_ProgramGuests.ProgramID AS Expr2, T_ProgramGuests.GuestName AS Expr3, T_ProgramGuests.GuestDescription AS Expr4, T_ProgramLinks.URL AS Expr5, T_ProgramLinks.Description AS Expr6 FROM T_ProgramGuests CROSS JOIN T_Programs CROSS JOIN T_ProgramLinks ORDER BY '" & id & "'"rs.Open strSQL,con 'open a connection to the database%><!-- Beginning of Display section --><br /><strong><% Response.Write RS ("GuestName") %> </strong> <% Response.Write RS("GuestDescription") %><br /><br />Related Links:<br /><li class='basic'><A HREF="<%= RS("URL") %>"><%= RS("Description") %></A></li><!-- End of Display section --><!-- END OF THE GUESTS AND LINKS SECTION --><%recProgram.Closecon.Closeset recProgram = nothingset con = nothing%> The T_ProgramGuests table contains a total of 10 records but I only see the one being displayed when I test the page. I need to be able to see the other 9 but only by id number. Now the id part works. I can type in a different number at the end of the URL and get the matching story content but below that the guestname and url is always the same one and is not related to the above content. But it should be.Here is a text sample of what the output looks like now.Weekday11/21/2005 10:00 amCulinary Catastrophes!!You torched the turkey. You dropped the lasagna and it landed face down on the floor....Guests: (the names here are in bold)John Doe executive chef and owner of ABC Restaurant.Greg Smith food writer, chef and regular contributor to the...Related Links: (these are text links, blue text with underline)ABC RestaurantGreg SmithMy section of data is below. The above we already do all the time.Jane Doe author of five novels and seven previous nonfiction books...Related Links: (this is a text link, blue text with underline)Jan Doe interviewed by Susan Smith, CBCWhy do I always see Joan Smith and not Greg Smith? My section being the guestname and link should match the story guest names and links. Here is what the URL looks like when I test using an id number of my choice.http://Server IP/test/defaultprogram4.asp?ID=9785What am I doing wrong with my select code? Or is my problem the asp display code? |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-04-20 : 14:40:51
|
you need to loop through the recordset to process all the rows.while not rs.eof ... do stuff here rs.movenextloooprs.close - Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
erico
Starting Member
34 Posts |
Posted - 2007-04-20 : 15:41:05
|
Jeff,Thanks but this is how I started originally. I changed to the asp code to display the records. It's a hassle displaying it using that method. So is the problem with the asp display code or the sql? |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-04-20 : 15:59:37
|
quote: Originally posted by erico Jeff,Thanks but this is how I started originally. I changed to the asp code to display the records. It's a hassle displaying it using that method. So is the problem with the asp display code or the sql?
huh .... ? What are you talking about? I have no idea what that means. I am not telling you to change anything major or to not use ASP, I am simply telling you that if you want to access all of the rows returned by a Recordset you need to LOOP through the contents of the recordset, which you are not doing in your code. Are you familiar with how an ADO recordset works? All you are doing is opening a recordset and displaying the contents of the first row, and that's it. If you want to return ALL of the rows, you have to call the moveNext method over and over until you reach the EOF for the recordset, as my simple example shows. Didn't we already go through this ????http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81013Also -- PLEASE STOP POSTING LONG LINES OF CODE WITH NO BREAKS !! it stretches out the entire screen and makes it very tough to read and write posts. Please be considerate and put breaks within your CODE section. Thanks in advance. you will find very few people will bother trying to read your posts to help you because they have to scroll left to right over and over for each line as they try to read it.- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
erico
Starting Member
34 Posts |
Posted - 2007-04-20 : 16:10:20
|
Ok I can try to use ado instead of raw asp and html to handle displaying of the data. Also last I checked all caps means yelling. Please dont yell at people in forums. Your point is well taken without it. I understand the concept of going through the recordset over and over until you reach the end. I learned that in college in the 80's. But ASP and SQL are new to me as I have been working in different areas of IT.I will edit my post and shorten the code so it doesn't stretch across the screen and cause people grief and I will try to remember not to do that in future posts.Thanks for being straight up about it. Sometimes even veterans of IT need to be reminded of the basics. |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-04-20 : 16:17:24
|
quote: Originally posted by erico Ok I can try to use ado instead of raw asp and html to handle displaying of the data.
I really think you need to step back a bit and learn more about the technology you are using. You ARE using ADO in your existing code; ADO is how you retrieve data from a database in an ASP page. Database <-- ADO <--- ASP Page ---> HTMLThat's basically how it works. ADO is a library that you use in your ASP page to access a database; your ASP page then loops through the results returned to generate HTML. that's basically it.Note that this changes quite a bit in ASP.NET, but it does not appear that you are using that so it's irrelevant for now.I hope this helps to clear things up; you seem very confused with the technology you are trying to program in. I strongly recommend getting a decent book or going through some tutorials to really get a handle on the basic concepts.- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-04-20 : 16:21:49
|
side note -- you only need to add manual line breaks within your CODE tags, not for all your text. Everything wraps automatically except text surrounded in CODE tags.- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
erico
Starting Member
34 Posts |
Posted - 2007-04-20 : 16:30:02
|
I found the original I tried using what your suggesting. Here is the code. Hopefully it wont stretch out this time.<table border="1" width="100%"> <tr> <%for each x in rs.Fields response.write("<th>" & x.name & "</th>") next%> </tr> <%do until rs.EOF%> <tr> <%for each x in rs.Fields%> <td><%Response.Write(x.value)%></td> <%next rs.MoveNext%> </tr> <%loop rs.close conn.close%></table> The problem I had with this is how to work with the x or to code it more specific to meet my needs. Your right I dont understand the technology I'm working with. Thats why I use forums. I'm not the one who wrote these asp pages. It was a crew that worked here long before I started and they left no documentation. Yes I have books both sql and asp but books only explain basics. If your lucky you might get some examples in them that relate at least some what to your project.I'm well aware that I need to learn. No argument there but I dont have the luxury of taking several months to learn it. I need to get this working in the next two weeks. That of course is my problem. I dont expect people in forums to write out the answers for me. That would be expecting too much and would not fit with IT of the 21st century.I'm only asking that someone help me think through it logically and maybe provide a code example of how I might be able to solve it. I'm not strong in VB, ASP or SQL. All of which I'm trying to learn as I go. The point of a forum is to help each other out not to tell everyone to go read a book. If all answers were in books I would never need to use a forum and I'm not apologizing for using them either. |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-04-20 : 16:48:33
|
erico -- you might be surprised if you opened one of those books this weekend and attempted to sit down and read some of it. The basics are what you need! These are all core, basic fundamentals of ASP that you need to know before you can go around messing with code hoping that it works! It doesn't take months, just a few hours here and there. It is ironic that you feel the books don't help you because they are too basic, yet the basics are EXACTLY what you need help with! Guess how I learned ASP? I didn't randomly open up ASP pages written by others and randomly poke around and change things to see what happens; I read a book. Took a few nights here and there. I did some tutorials. I did a simple "hello world". I did a very simple database query and learned how to loop through the tables. I practiced HTML. And it only took a few days! (believe me, I am no genius). Don't make excuses, just LEARN IT! Everyone complains "I have no time to do all that!! It will take months!!" and instead they end up spending months wading around in a mess of code that they don't understand, when it would have only taken a day or so to step back and learn the core concepts that they are using. And you are ALWAYS better off when you know exactly why the code you wrote works, instead of randomly stumbling upon something that SEEMS to work or getting someone in a forum somewhere to give you code that you don't understand! As for getting help in forums -- absolutely. Great idea. But neither me nor anyone else here can write a post for you that will teach you everything you need to know about all the concepts and terminology regarding ASP and ADO and all that. We can only answer specific questions. A key thing to learn in this field isn't any specific technology at all, but rather the skill of identifying exactly where it is that your code isn't working right, eliminating the unimportant things that you already know or understand, and posting a short and concise but also clear and specific question when you need some help. Dumping tons of code and saying "it doesn't work! please help!" is not the way to go. Anyway, that's my advice. Take it or leave it. - Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
|