Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a on click to get another value

Status
Not open for further replies.

Figzus

Programmer
Joined
Mar 21, 2005
Messages
36
Location
US
Okay here is what Im trying to do with this code. Im trying to take this value <%Response.Write (rsMOWebIndex("NodeName"))%> and when you click on the NodeName it will show all of the article names thats associated with it in the database. If anyone can help me that would be great. Thanks
 
i would do something like

<a href="yourpage.asp?id=<%=rsMOWebIndex("id")%> "><%=rsMOWebIndex("NodeName")%></a>

when you click - you should now have a querystring

have your

sql like this

sql="select * from tblname where id="&request("id")

conn.execute(sql)
 
figzus,

looks like a unique nodename can have more than 1 article
one-to-many relationship

one-node can have many-articles

can a unique article be associated to more than one nodename?
many-to-many relationship

many-articles can be related to many nodenames

Please post the db name and fields, thanks

BSL
 
Sorry about being late putting this back up but here is my code. I have a Do While Loop finding all the Nodes with a Parent ID=0. The nodes have their own ID thats attached to an article. An Article can belong to 1 or many nodes and Nodes can belong to 1 to many articles. When I click on the Node Name that shows up I want it to show all the articles thats associated with it.

<body>
<div id="header">
<!-- #include file="incConnection.asp" -->
<!-- #include virtual="/custom/header.html" -->
<h2>MO Web Index</h2>
<div id="help"></div>
</div>
<div id="content">
<div id="sub-nav">
<div id="search">
<h2>Search</h2>
<form id="form1" name="form1" action=" method="post">
<p>&nbsp;<INPUT id="txtSearch" size="25" search="txtSearch" width="300"></p>
<p>&nbsp;</p>
<input class="submit" id="Image1" type="image" height="20" width="80" src="/images/submit.gif"
value="Search" name="submit">
</form>
</div>
</div>
</div>
<div id="main-content">
<form method="post" name="MainForm" ID="MainForm">
<%

dim adocon
dim rsMOWebIndex
dim strSQL



set adocon=server.CreateObject("ADODB.Connection")


set rsMOWebIndex=server.CreateObject("ADODB.Recordset")

adocon.ConnectionString=gstrCon



strSQL = "SELECT tblNodeName.NodeID, tblNodeName.NodeName, tblNodeName.ParentID, tblArticle.ArtID," & _
" tblArticle.ArtName, tblTieIn.ArtPath " & _
" FROM tblNodeName INNER JOIN (tblArticle INNER JOIN tblTieIn ON tblArticle.ArtID = tblTieIn.ArtID)" & _
" ON tblNodeName.NodeID = tblTieIn.NodeID " & _
" WHERE (((tblNodeName.ParentID)=0)) "


adocon.Open
rsMOWebIndex.Open strSQL,adocon

'Loop through the recordset
%>
<%Do While not rsMOWebIndex.EOF%>


<%Response.Write ("<br>")%>
<%Response.Write ("<b>")%>
<%Response.Write ("<a>")%>

<%Response.Write (rsMOWebIndex("NodeName"))%>>

<%Response.Write ("<br>")%>
<%rsMOWebIndex.MoveNext%>

<%Loop

rsMOWebIndex.Close
adocon.Close
set rsMOWebIndex=nothing
set adocon=nothing
%>
</form>
</div>
<DIV class="footer"></DIV>
</body>
 
this i what i think you need, first you need 2 pages,

first page - list the nodes, using a sql like this,

"select NodeID, NodeName from tblNodeName"

then loop through all something like this
<%
Do While not rsMOWebIndex.EOF
nodename=rsMOWebIndex("NodeName")
nodeid=rsMOWebIndex("NodeID")

Response.Write "<a href=""secondpage.asp?nodeid="&nodeid&""">"&nodename&"</a>"
Response.Write "<br>"

rsMOWebIndex.MoveNext

Loop
%>

second page - will display all the articles associated to the chosen node (grabbed from the querystring)

sql would look something like

"select ArtID, ArtName from tblArticle where Nodeid="&request("nodeid")

then layout the rest to display the details
 
instead of displaying article links right away and cluttering the page why not use a select box containing the nodes in databse and have user select which node he wants to see an article on and then do stevens links for each artcle instead of node. this code uses a select box populated by db ...user selects...links pop up and user can noe choose the article by relevance. it is a 3 tbl relationship...a many-to-many setup... 1 node table 1 junction table to link nodde and atricles making the many to many and 1 article table.....so if you wanted to create a form to update this database simply get the id of the new record using the addnew method...get that id and insert into the tblNodes_Articles table and same when doing the article...i'll have a live version later of this code...it's very basic but may int you in the right direction...my cheap(free) asp site is down...go figure...good luck!

BSL\
Code:
 <!-- #include file="incConnection.asp" -->
 
<html>
 <head>
 </head>
 <body>
  <h2>MO Web Index</h2>
  
<%
  category = Request.Form("category")
  article = Request("article")
  title = Request("Title")
%>

   <form action="articles.asp" method="post">
    <select name="category" value="<%=categoryid%>">
     <option value="">--Node Category--</option>
<%
  strSQL="SELECT NodeID, Node FROM tblNodes;"
  objRS.Open strSQL, objConn

  If objRS.EOF Then

  Else

     Do While Not objRS.EOF
   
%>
    
    <option value="<%=objRS("NodeID")%>"><%=objRS("Node")%></option>
     
<%     
     objRS.MoveNext
     Loop 
     objRS.Close
  End If
%>
    </select>
    <input type="submit" value="find" name="submit" value="Find">
   </form>
  <hr>
               
<% 
  If category <> "" Then                      
                                 
        strSQL="SELECT tblNodes.NodeID, tblNodes.Node, tblArticles.ArticleID, tblArticles.Title, tblArticles.Article " & _
               "FROM tblNodes INNER JOIN (tblArticles INNER JOIN tblNodes_Articles " & _
               "ON tblArticles.ArticleID = tblNodes_Articles.ArticleID) " & _
               "ON tblNodes.NodeID = tblNodes_Articles.NodeID " & _
               "WHERE tblNodes_Articles.NodeID =" & category & " ORDER BY Title;"
 

       objRS.Open strSQL, objConn
  
      'Loop through the recordset

       If objRS.EOF Then
           Response.Write "Sorry, no articles at this time"

       Else  

           i = 0
           Do While Not objRS.EOF
           i = i + 1
          
            
     	     Response.Write i & ". <a href=""articles.asp?article=" & objRS("ArticleID") & "&title=" & objRS("Title") & """>" & objRS("Title") & "</a><br>"
           
           objRS.MoveNext
           Loop
           objRS.Close
      End If
   End If

       If article <> "" THEN

           strSQL="SELECT ArticleID, Title, Article FROM tblArticles WHERE ArticleID=" & article & ";"
            objRS.Open strSQL

                 
%>
   
   Article <%=objRS("ArticleID")%><br><u><b><%= objRS("Title")%></b></u>
   <p>
   <textarea rows="20" cols="50" readonly><%=objRS("Article")%></textarea>
   </p>
    

<%
       objRS.Close
       End If
     
    
          SET objRS = Nothing
       
       objConn.Close
       SET objConn = Nothing
   
%>
 </body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top