473,765 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hyperlink with drop down links from a mysql database

17 New Member
HI,

I'm having alot of problems trying to figure out how to create drop down links from a hyperlink on my homepage.

I have a hyperlink called Programs (this is for a community centre)

When the Programs hyperlink is selected I would like a drop down of link from my programs mysql table to be displayed. So far, it takes my mysql data and puts it as link but on it's own. I'm not sure how to put it under my Programs hyperlinks. Also description is just the field name in my table. I do not want it to appear under my Program Hyperlink. I'm scared to mess around too much because as of now the hyperlinks do show up on their own.

Help would be greatly appreciated.

Here is my current code below.
Expand|Select|Wrap|Line Numbers
  1. <%   Dim conn 
  2. 'Create an ADODB connection
  3.  Set conn = Server.CreateObject("ADODB.Connection")
  4.  
  5. 'Open the database
  6.  conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentre;UID=mona.ramsay;PWD=puke_9;"
  7.  
  8. 'Execute the SQL and assign to our Recordset
  9. set rs = Server.createobject("ADODB.recordset")
  10. sql = "SELECT description FROM programtbl"
  11.  
  12.  Dim selected, query
  13. ' get the item that was passed in the querystring.
  14. selected = Request.QueryString("LinkChosen")
  15.  
  16. <a href="http://localhost/ValourCommunityCentre/ValourCC.asp?LinkChosen=Programs"> Programs</a>
  17.  
  18. rs.Open sql, conn%>
  19.  
  20. <% Do While NOT RS.EOF 
  21.     Response.Write("<a href='http://" & rs.Fields.Item("description").Value & "'>" & rs.Fields.Item("description").Value & "</a>")%>
  22.  
  23. <% 
  24. RS.Movenext
  25. loop%>
  26.  
  27. <table>
  28.  
  29.     <tr>
  30.     <% for each x in rs.fields
  31.     response.write("<th>" & x.name & " </th>")    
  32.    next%>
  33.   </table>
  34.  
  35.   <%  do until rs.EOF%>
  36.  
  37.     <%for each x in rs.fields
  38.     style="width: 2px"> Response.write(x.value)%>
  39.     <%next
  40.  
  41.     rs.movenext%>
  42.  
  43.    <%loop
  44.  
  45.  rs.close
  46.  conn.close
  47. %>
Sep 9 '07 #1
5 2906
jhardman
3,406 Recognized Expert Specialist
It looks like there are some errors in your code. I guess I may have messed something up when I was editing it, but I thought I just removed a little white space. One problem is that you are scrolling through all of the files to write the description, this leaves you at the last record (or past it) when you want to list things again. The first do...loop is completely unnecessary if you don't want to show the descriptions.

Anyway, showing the program names in a drop-down select is pretty easy, but it depends on what it is named in the database. For example, if the db has a field called "programNam e" then you can write it like this:
Expand|Select|Wrap|Line Numbers
  1.  <select>
  2. <%
  3. rs.movefirst
  4. 'this line might cause an error depending on your cursor type
  5. 'it just moves to the first record in the recordset and isn't necessary if you
  6. 'haven't moved through them yet
  7.  
  8. do until rs.eof
  9.    response.write "<option value=" & chr(34) & rs("programName") & chr(34)
  10.    response.write ">" & rs("programName") & "</option>" & vbNewLine
  11.    rs.movenext
  12. loop %>
Notice, this just shows a list in a dropdown select, I didn't put in any functionality. Where do you want to go from here? Did this help?

Jared
Sep 10 '07 #2
mramsay
17 New Member
Hi there,

I am really confused. I am a beginner with ASP and do not follow you.

I've changed my code, but when I run it, I can see the values from the description field and the field name description at the bottom of my webpage.

I can't seem to get the values to be hyperlinks when I select the Program hyperlink.

Here's my code now, I know I am missing something somewhere.
Expand|Select|Wrap|Line Numbers
  1. <%   Dim conn 
  2. 'Create an ADODB connection
  3.  Set conn = Server.CreateObject("ADODB.Connection")
  4.  
  5. 'Open the database
  6.  conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentre;UID=myUID;PWD=myPWD;"
  7.  
  8. 'Execute the SQL and assign to our Recordset
  9. set rs = Server.createobject("ADODB.recordset")
  10. sql = "SELECT description FROM programtbl"
  11.  
  12.  Dim selected, query
  13. ' get the item that was passed in the querystring.
  14. selected = Request.QueryString("LinkChosen")
  15.  
  16.  
  17.   '<a href="http://localhost/ValourCommunityCentre/ValourCC.asp?LinkChosen=Programs"> Programs</a>
  18.  
  19. rs.Open sql, conn%>
  20.  
  21. <table>
  22.  
  23.     <tr>
  24.     <% for each x in rs.fields
  25.     response.write("<th>" & x.name & " </th>")   
  26.  
  27.    next%>
  28.   </table>
  29.  
  30.  
  31.   <%  do until rs.EOF%>
  32.  
  33.     <%for each x in rs.fields
  34.     style="width: 2px"> Response.write(x.value)%>  
  35.  
  36.     <%next
  37.  
  38.  
  39.     rs.movenext%>
  40.  
  41.  
  42.    <%loop%>
  43.  
  44.  
  45.  
  46. <select>
  47.  
  48. <%    
  49.  
  50.  
  51.  
  52. 'this line might cause an error depending on your cursor type
  53. 'it just moves to the first record in the recordset and isn't necessary if you
  54. 'haven't moved through them yet
  55.  
  56. do until rs.eof
  57.    response.write "<option value=" & chr(34) & rs("description") & chr(34)
  58.    response.write ">" & rs("description") & "</option>" & vbNewLine
  59.    rs.movenext
  60. loop %>
  61.  
  62. <%rs.close
  63.  conn.close %>
  64.  
  65. </select>
Sep 11 '07 #3
jhardman
3,406 Recognized Expert Specialist
Hi there,

I am really confused. I am a beginner with ASP and do not follow you.

I've changed my code, but when I run it, I can see the values from the description field and the field name description at the bottom of my webpage.

I can't seem to get the values to be hyperlinks when I select the Program hyperlink.

Here's my code now, I know I am missing something somewhere.
I think it's clear that you are missing something, there are lines in your code that don't make any sense. Partly because of that I don't know what you are trying to turn into a hyperlink. I don't even know what you are talking about when you say "when I select the Program hyperlink", What does that mean?

I'm not trying to be a jerk, I just don't understand you and it seems apparent from your code that you don't know how to get what you want. Don't get too stressed out about this. Let's go back over your code and I'll try to explain exactly what it is doing.
Expand|Select|Wrap|Line Numbers
  1. <%   Dim conn 
  2. 'the asp script will connect to a database with an ADODB connection
  3.  Set conn = Server.CreateObject("ADODB.Connection")
  4.  
  5. 'gives the script the details of how to connect, and tells it to connect to the db
  6.  conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentre;UID=myUID;PWD=myPWD;"
  7.  
  8. 'a recordset is just that, a set of records, and you are going to put the info from 
  9. 'the db into a recordset to make it easier to use.  "SQL" is a standard way to 'ask databases for information, it can be used by most types of databases
  10. set rs = Server.createobject("ADODB.recordset")
  11. sql = "SELECT description FROM programtbl"
  12. 'the only thing you are looking up in the db is one field called "description" in
  13. 'one table called "programtbl".  Everything else in the database is being ignored
  14. 'If you want to look up more data, I would change
  15. 'this to "SELECT * FROM programtbl" this puts all of the data into your recordset
  16.  
  17. Dim selected, query
  18. ' get the item that was passed in the querystring.
  19. 'reading through your code, although you act like someone would send data to
  20. 'this page, you are not using this data in any way.
  21. selected = Request.QueryString("LinkChosen")
  22.  
  23.   '<a href="http://localhost/ValourCommunityCentre/ValourCC.asp?LinkChosen=Programs"> Programs</a>
  24. 'this line is a link, but since it begins with an apostrophe it will be ignored.  
  25. 'This is how we write comments for others who read our code.
  26.  
  27. 'this line is where you actually ask the db for information which you put
  28. 'in your recordset, it specifies which db connection you are using, and the sql 
  29. 'query you wrote above for what parts of the db you want
  30. rs.Open sql, conn%>
  31.  
  32. <table>
  33.  
  34.     <tr>
  35.     <% for each x in rs.fields
  36.    'this for each ... next loop looks through every field in your recordset
  37.    'and prints the name of the field into the header of the table. This is 
  38.    'kind of a standard way to list everything in your recordset
  39.     response.write("<th>" & x.name & " </th>")   
  40.    'since your recordset only has one field, it is only printing the following:
  41.    '"<th>description</th>".  The great thing is that if you changed the SQL 
  42.    'query to "SELECT * FROM ..." then this would have more fields, or if it said 
  43.    '"SELECT programName FROM ..." then it would show programName.
  44.  
  45.    next %>
  46.   </table>
  47.    <!-- The above line ends the table.  it doesn't make sense to me to end the 
  48.    table here.  Surely the other fields need to be in the same table, right?  
  49.    Anyway, this is how we write comments in HTML -->
  50.  
  51.   <%
  52.   do until rs.EOF
  53.    'this says you expect to go through every record in your recordset
  54.  
  55.    'there appears to be a line missing here which says:
  56.    'response.write "<tr>", this would start a new line in the table %>
  57.  
  58.     <%for each x in rs.fields
  59.    'this for each ... next loop should list the contents of every field in one
  60.    'record, but the next line appears to be garbled.  I believe it should say 
  61.    'something like this:
  62.    'response.write "<td>" & x.value & "</td>" & vbNewLine
  63.     style="width: 2px"> Response.write(x.value)
  64.  
  65.    next
  66.  
  67.    'there appears to be a line missing here which says:
  68.    'response.write "</tr>" 
  69.    'this would finish off the row of your table in preparation to move to the next
  70.    'record
  71.  
  72.     rs.movenext
  73.    'this moves to the next record in your recordset %>
  74.  
  75.     <%
  76.    loop
  77.    'this sends you back to the point marked "do" %>
  78.    <!-- I would end the table here when you finish going through the loop rather 
  79.    than the place mentioned above -->
  80.  
  81. <!-- this next line starts a dropdown select.  I wrote this code because I thought
  82. you wanted one.  Unfortunately, I didn't understand why you wanted it, so
  83. it probably doesn't show you what you want and I didn't make this select do anything, it just sits there -->
  84. <select>
  85. <%    
  86. rs.movefirst
  87. 'this line moves you back to the first record, otherwise you would be at the end
  88. 'and that wouldn't do you any good.  I notice you took it out but left in the 
  89. 'comment I made.  That is puzzling.  did it cause an error?
  90.  
  91. do until rs.eof
  92.    'notice I am just going to scroll through the records and put the description
  93.    'from the db into the options of the select.  This probably isn't very useful
  94.    'but it does demonstrate how info from the db can be incorporated into
  95.    'the web page.  I'm going to write it a little different this time just because
  96.    'it might make more sense, but it actually does the exact same thing
  97.    %>
  98.    <option value="<%=rs("description")%>"><%=rs("description")%></option>
  99.    <%
  100.    rs.movenext 'this just moves to the next record
  101. loop ' this just goes back to the beginning of the do ... loop %>
  102.  
  103. <%rs.close
  104.  conn.close
  105. 'these lines close the recordset and the db connection.  They are actually not 
  106. 'necessary because ASP scripts automatically close all open connections at 'the end of the script, but some programmers include these lines to be safe %>
  107.  
  108. </select>
  109. <!-- this line ends the drop down select -->
I hope my explanation helps you understand a little of what is going on. I feel like I know pretty well what your script is doing, but it isn't what you want and I don't understand what you want. You said you want hyperlinks, but what part do you want to make into hyperlinks and where should they take you? I give you full marks for trying this out on your own, a lot of us started out like that before we fully understood what we were doing. However, if you don't do better at explaining what you need, I will not be able to help you any more.

Jared
Sep 11 '07 #4
mramsay
17 New Member
Hi there,

I've read over your comments a few times. I guess I'm not being clear enough in explaining what I want my code to do.

Well here goes.

I am working on a Community Centre Website.

I am using visual studio 2005 coding with asp and html. My home page consists of the name of the Community Centre and I have hyperlinks on the right had side, very common in websites.

One of my hyperlinks on the webpage is Programs. What I am trying to do is when a user or myself selects the Programs hyperlink, he/she will see a list of other hyperlinks related to Programs such as Hockey, Baseball, etc. for an example. Then the user can select Hockey or baseball and it will bring them to a page of information regarding the Hockey program.

I do not want a drop down list.

Example:

Progams - hyperlink when selected
Baseball - hyperlinks will be displayed on the home page right under
Hockey
Programs.

My program table consists of more information than description, but, I only want the records under description to be displayed when Programs is clicked. Description is the column heading. Baseball and Hockey are my fields under description.

I hope this is easier to understand.
Sep 13 '07 #5
jhardman
3,406 Recognized Expert Specialist
Hi there,

I've read over your comments a few times. I guess I'm not being clear enough in explaining what I want my code to do.

Well here goes.

I am working on a Community Centre Website.

I am using visual studio 2005 coding with asp and html. My home page consists of the name of the Community Centre and I have hyperlinks on the right had side, very common in websites.

One of my hyperlinks on the webpage is Programs. What I am trying to do is when a user or myself selects the Programs hyperlink, he/she will see a list of other hyperlinks related to Programs such as Hockey, Baseball, etc. for an example. Then the user can select Hockey or baseball and it will bring them to a page of information regarding the Hockey program.

I do not want a drop down list.

Example:

Progams - hyperlink when selected
Baseball - hyperlinks will be displayed on the home page right under
Hockey
Programs.

My program table consists of more information than description, but, I only want the records under description to be displayed when Programs is clicked. Description is the column heading. Baseball and Hockey are my fields under description.

I hope this is easier to understand.
OK, I think this makes a little more sense. One of the things that confused me was your use of the word "select" which in HTML refers to a drop-down where a user can select an option from a list.

There are a couple ways to achieve similar effects. It might make most sense to put these all on one page like this:
Expand|Select|Wrap|Line Numbers
  1. <html><head><title></title></head><body>
  2.  
  3. <div style="position: absolute; left: 0px; top: 0px; height: 100%; width: 150px;">
  4. <ul>
  5. <li>Calendar</li>
  6. <li><a href="thisPage.asp?display=programs">Programs</a></li>
  7. <li>Contact Info</li>
  8.  
  9. </ul>
  10. </div>
  11. <div style="position: absolute; left: 150px; top:0px; height: 100%;">
  12. <%
  13. dim query, conn, rs
  14.  
  15. if request.querystring("display") = "programs" then
  16.     Set conn = Server.CreateObject("ADODB.Connection")
  17.     'gives the script the details of how to connect, and tells it to connect to the db
  18.      conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr  e;UID=myUID;PWD=myPWD;"
  19.  
  20.     'a recordset is just that, a set of records, and you are going to put the info from
  21.     'the db into a recordset to make it easier to use.  "SQL" is a standard way to 'ask databases for information, it can be used by most types of databases
  22.     set rs = Server.createobject("ADODB.recordset")
  23.     query = "SELECT description FROM programtbl"
  24.  
  25.     rs.open query, conn
  26.  
  27.     response.write "Programs:<br>"& vbNewLine & "<ul>"
  28.  
  29.     do until rs.eof %>
  30.         <li><a href="detailPage.asp?program=<%=rs("description")%>"><%=rs("description")%></a>
  31.         </li>
  32.         <%
  33.         rs.moveNext
  34.     loop
  35. %>
  36. </div>
  37.  
  38. </body></html>
Try this and see if it comes close to what you want.

Jared
Sep 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
5758
by: leegold2 | last post by:
Like so many questions this involves MYSQL and the PHP (or Perl) layer. I'm going to have html in text fields and there's going to be what normally would be an internal link to another place in the same document. But in this case, Code: <a href="#futherdown">next title</a> is not in the html document. When a user clicks this link I want to
1
2504
by: jonnytansey2 | last post by:
Can anyone out there give me a pointer regarding creating a dynamically-generated drop-down list connected to an array? And is that question as clear as chocolate spread? Here's what I've got. I'm using PHP and MySQL database. I'm customizing some calendar software, and I want the user to fill in a form by selecting a title from a drop-down list, generated by my MySQL database. However, the program I'm customizing uses arrays, which is...
3
1552
by: phil | last post by:
We are developing specs. for a website for a nonprofit org, with database for membership related functions. But..question is regarding drop down menu links. We will have 20 category-pages, and each page will have 30-50 links- unique to that page, so 1000+ total for site- on a drop down menu. Need we assume that such links (both plain english description to appear on site, and actual URL to link to- so 2 pieces data really for each...
3
1904
by: Raja | last post by:
I have a datagrid, it has dropdown box as a column and i have one more column that has hyperlink. The NavigateURL for the hyperlink is to open a new window with a query stirng parameter as the selected value of the drop down... here is how it looks like <asp:datagrid....> .... <asp:TemplateColumn> <ItemTemplate>
1
1987
by: brino | last post by:
hi all ! i'm kind of new to MYSQL so am still learning basics. my question is how do you create a drop down list in a field in an SQL database ? thanks brino
5
18725
by: ashok893 | last post by:
I'm using two drop down list ina form. I have generated the first drop down list from MySQL database. When i select an option from first drop down list, i have to generate second drop down list options by the selected value of first drop down list from MySQL database. For example, the first drop down list contains Animals, Birds... If i select the Animal option, the second drop down list should show like Lion, Tiger.... Both lists should...
2
5255
by: Boujii | last post by:
Greetings, I have been attempting to make a drop down menu of countries. From this menu I wish to create a variable in order to INPUT into mysql database. I have no trouble making the drop down menu, but I am unable to store a variable for it. Here is a rough copy of what I am making: <html> <head> <title>Add New MySQL User</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>
4
9296
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me if it works, and if it does not, tell me why it does not work. Thanks.
1
2966
by: student2008 | last post by:
Sorry about the title its a tricky one. I have a form which allows me to add a question and answers into a mysql database via a combination of, if a certain option is chosen and the reset button is pressed then a text box appears to enter a new question or answer or both. the newly entered data is then inserted into mysql. The newly entered data is then requested by mysql_fetch_array() to be displayed as options in the drop down list. If...
0
9393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10153
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8830
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6646
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.