Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 27th, 2005, 02:07 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default how to inner join tables

I have a MSAccess 2000 mdb where 2 tables must be connected with a fieldname "book_spoke".
This is what I have so far. Is it right? The purpose is to find within the search result all the book_spoke s and link with the proper url for each book_spoke.
Code:
<%
'Option Explicit
'Response.End 
Response.Buffer=false

Dim letter
Dim letterSQL
Dim str
letterSQL = "SELECT bible.book_spoke, "
letterSQL = letterSQL & "bible.book_spoke, "
letterSQL = letterSQL & "biblewheel_url.url "
letterSQL = letterSQL & "FROM bible INNER JOIN biblewheel_url "
letterSQL = letterSQL & "ON bible.book_spoke = "
letterSQL = letterSQL & "biblewheel_url.book_spoke "
'    letterSQL = "SELECT bible.book_spoke, "
'    letterSQL = letterSQL & "biblewheel_url.url "
'    letterSQL = letterSQL & "FROM biblewheel_url "
'    letterSQL = letterSQL & "INNER JOIN bible "
'    letterSQL = letterSQL & "ON biblewheel_url.book_spoke = "
'    letterSQL = letterSQL & " bible.book_spoke "

    strConn = GetConnectionString()

Set letter = Server.CreateObject("ADODB.Recordset")
    letter.CursorLocation = adUseClient

    letter.Open letterSQL, strConn, adOpenForwardOnly, adLockReadOnly
str = str%>

http://www.biblewheel.com
<%=letter("url")%>

<%

    letter.Close
    set letter = Nothing
%>
What I did was to make a parent child relationship within the "query" section in the mdb. But I'm not sure if I need to do other things.

Learning of our true origins.

I feel sorry:

http://www.infowars.com/articles/wor...eknowledge.htm

Foreknowledge of A Natural Disaster
Washington was aware that a deadly Tidal Wave was building up in the Indian Ocean
 
Old January 27th, 2005, 02:21 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not sure why you are using client side cursor?

anyway this may help?

<%
'Option Explicit
'Response.End
Response.Buffer=false

Dim letter
Dim letterSQL
Dim str
letterSQL = "SELECT bible.book_spoke, "
letterSQL = letterSQL & "biblewheel_url.url As WebURL"
letterSQL = letterSQL & "FROM bible INNER JOIN biblewheel_url "
letterSQL = letterSQL & "ON bible.book_spoke = "
letterSQL = letterSQL & "biblewheel_url.book_spoke "


strConn = GetConnectionString()

Set letter = Server.CreateObject("ADODB.Recordset")


letter.Open letterSQL, strConn, adOpenKeySet, adLockOptimistic

WHILE NOT letter.EOF
%>
<a href="<%= letter("WebURL") %>"><%= letter("book_spoke")%></a><br>
<%
    letter.MoveNext
    Wend
    letter.Close
    set letter = Nothing
%>
 
Old January 28th, 2005, 06:35 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

I tried it. But it gave me error. So let me explain wht I intend to do.
for example. Here's the result:
http://n.1asphost.com/wheelofgod/kjv...s&optAction=on
If you look at the column of: Book #/
Book Spoke
You'll notice all the links in the images are the same:
http://www.biblewheel.com/Wheel/Spokes/Aleph_God.asp
which is the first url in the biblewheel_url table.

Learning of our true origins.

I feel sorry:

http://www.infowars.com/articles/wor...eknowledge.htm

Foreknowledge of A Natural Disaster
Washington was aware that a deadly Tidal Wave was building up in the Indian Ocean
 
Old January 31st, 2005, 01:35 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

I don't know if this helps simplify. But I highlight where the problem seems to be. There are 2 queries.

Code:
<% 'Option Explicit
Response.Buffer=false%>
<%
Const DB_NAME           = "kjv.mdb" ' Name of our database file
Const INTRO             = "introduction to the wheelofgod.asp"
Const THECYCLES         = "cycles.asp"
Const SCRIPT_NAME       = "kjv.asp"  ' Name of this script
Const SCRIPT_NAMES      = "kjvresp.asp"
const SCRIPT_SAVED      = "saved.asp"
Const SCRIPT_FEEDBACK   = "mailto.asp"
Const SCRIPT_TEXT       = "bibletext.asp"

Const RECORDS_PER_PAGE  = 10            ' Number of records per page

Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adCmdTableDirect = &H0200
Const adUseClient = 3

Private Function GetConnectionString()
    GetConnectionString =   "Driver={Microsoft Access Driver (*.mdb)};" & _
                "DBQ=" & Server.MapPath(DB_NAME) & ";" & _
                "UID=;PWD=;"
End Function
Set Conn = server.createobject("ADODB.Connection")
Conn.open GetConnectionString
%>
<%  Dim strConn     ' Database connection string
    Dim SQL         ' String that will have our SQL statments
    Dim RS          ' Recordset object
    Dim Keyword     ' Keyword for search
    Dim Keywordb
    Dim Keywordc
    Dim Keywordd
    Dim Keyworde
    Dim Keywordf

'pageing
    Dim nRecCount   ' Number of records found
    Dim nPageCount  ' Number of pages of records we have
    Dim nPage       ' Current page number
'query
    Dim iCounter
    Dim iLoopCount
    Dim aRecTypes
    Dim spoke       ' For dropdown
    Dim number

    Dim intRec

SQL= "SELECT * from bible where "

    ' Let's see what user wants to search for today :)
    Keyword = Trim(Request.QueryString("Keyword"))
    Keywordb = Trim(Request.QueryString("Keywordb"))
    Keywordc = Trim(Request.QueryString("Keywordc"))
    Keywordd = Trim(Request.QueryString("Keywordd"))
    Keyworde = Trim(Request.QueryString("Keyworde"))
    Keywordf = Trim(Request.QueryString("Keywordf"))
    spoke = Request.Querystring("spoke")
    number = Request.QueryString("number")


iCounter = 0

If   request.QueryString("text_data")="yes" then

  SQL = SQL & "text_data LIKE '%" & Keyword & "%' AND "  
  SQL = SQL & "text_data LIKE '%" & Keywordb & "%' AND "
  SQL = SQL & "text_data LIKE '%" & Keywordc & "%' AND "  
  SQL = SQL & "text_data LIKE '%" & Keywordd & "%' AND "
  SQL = SQL & "text_data LIKE '%" & Keyworde & "%' AND "
  SQL = SQL & "text_data LIKE '%" & Keywordf & "%'"

  iCounter = iCounter + 1

end if


If   request.QueryString("book")="yes" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "book LIKE '" & number & "'"

  iCounter = iCounter + 1

end if


If   request.QueryString("book_title")="yes" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "book_title LIKE '%" & number & "%'"

  iCounter = iCounter + 1

end if

If   request.QueryString("chapter")="yes" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "chapter LIKE '%" & number & "%'"

  iCounter = iCounter + 1

end if

If   request.QueryString("verse")="yes" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "verse LIKE '%" & number & "%'"

  iCounter = iCounter + 1

end if

If   request.QueryString("book_spoke")="Book_Spoke" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "book_spoke = '" & spoke & "'"

  iCounter = iCounter + 1

end if

If   request.QueryString("chapter_spoke")="Chapter_Spoke" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "chapter_spoke = '" & spoke & "'"

  iCounter = iCounter + 1

end if

If   request.QueryString("verse_spoke")="Verse_Spoke" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "verse_spoke = '" & spoke & "'"

  iCounter = iCounter + 1

end if

If Trim(Request.QueryString("recordType")) <> "" Then


  aRecTypes = Split(Request.QueryString("recordType"), ",")

  If IsArray(aRecTypes) Then 'This is a bit redundant, but it can't hurt
    SQL = SQL & " AND ("

    For iLoopCount = 0 To UBound(aRecTypes)
      If iLoopCount <> 0 Then
        SQL = SQL & " OR "
      End If

      SQL = SQL & "recordType = '" & trim(aRecTypes(iLoopCount)) & "'"
    Next
  End If
  SQL = SQL & ")"
End If

SQL = SQL & " ORDER BY id ASC "
%> <%
set RS = Server.CreateObject("ADODB.Recordset")
rs.PageSize= RECORDS_PER_PAGE
rs.CursorLocation = adUseClient
rs.CacheSize = 20
RS.Open SQL, Conn, adOpenForwardOnly, adLockReadOnly
'RS.Open SQL, Conn, 3, 1, &H0001 ' Open recordset with appropriate parameters.
rscount=rs.RecordCount
rspage=rs.PageCount

if request.querystring("page")="" then 
   page=1
else
   page=cint((request.querystring("page")))
end if
%>

<%
If Not rs.EOF Then
Response.Write "The King James Bible has " & rs.RecordCount &_
" verses found matching ""<b>" & Keyword & "</b>&nbsp;+&nbsp;" &_ 
"<b>" & Keywordb & "</b>&nbsp;+&nbsp;" &_
"<b>" & Keywordc & "</b>&nbsp;+&nbsp;" &_
"<b>" & Keywordd & "</b>&nbsp;+&nbsp;" &_
"<b>" & Keyworde & "</b>&nbsp;+&nbsp;" &_
"<b>" & Keywordf & "</b>&nbsp;" &_
" in Spoke <b>" & spoke & "</b>.<br>" 
Response.Write "There are " & rs.PageCount & " page(s) of result(s).<br>"
Response.Write "The current page is " & Page & ".<p>"
End if%>

<%If rs.BOF and rs.EOF Then%>
<H2 align="center">We did not find a match of <i><b>"<%=Keyword%>&nbsp;<%=Keywordb%>&nbsp;<%=Keywordc%>"!</b></i></H2>
<h5 align=center><A HREF="<%=SCRIPT_FEEDBACK%>">Feedback Forum</A>      |
<A HREF="<%=SCRIPT_NAME%>">Back To Search Page</A></h5>
<%Else%> 
<table border="1" cellspacing="1" bgcolor="#0066CC">
<tr style="height:12.75pt">
 <th bgcolor="#800000">
 <form align="center" method="get" action="<%=SCRIPT_SAVED%>" id=form1 name=form1>Select<br>
 <select size="1" name="choices" id="choices">
        <option SELECTED VALUE="">None</option> 
        <option VALUE="001">Delete</option>
        <option VALUE="002">Email to:</option>
        <option VALUE="003">Print</option>
        <option VALUE="004">Save in:</option>
 </select><input type="submit" value="OK" name=submit1><br>
<input type='checkbox' onclick='checkAll(this.form,this)' value="check all" name="ck<%CStr(id)%>">
 Select All</th>
 <th bgcolor="#800000">Book Title</th>
 <th bgcolor="#800000">Book #/<br>Book Spoke</th>
 <th bgcolor="#800000">Chapter #/<br>Chapter Spoke</th>
 <th bgcolor="#800000">Verse #/<br>Verse Spoke</th>
 <th bgcolor="#800000">Text</th>
  </tr>
   <%
' skip the dummy records
if not rs.eof then
rs.Move (page-1)*rs.pagesize
end if
if not rs.eof then
     ' Display the records
for i=1 to rs.pagesize%> 
<td width="100" nowrap rowspan="2" align=center BGCOLOR="#FFFFFF">
<input type="checkbox" name="ck<%CStr(id)%> value="<%=rs("id")%>">
<%=rs("id")%></span>
</td>

<td width="100" nowrap rowspan="2" align=center BGCOLOR="#FFFFFF">
<%=rs("book_title")%></span>
</td>
      
<td width="100" align=center BGCOLOR="#FFFFFF">
<%=rs("book")%></span>
</td>

<td width="100" nowrap align=center BGCOLOR="#FFFFFF">
<%=rs("chapter")%></span>
</td>

<td width="100" nowrap align=center BGCOLOR="#FFFFFF">
<%=rs("verse")%></span>
</td>

<td width="350" nowrap rowspan="2" align=left BGCOLOR="#FFFFFF"> 
<b><%=rs("book_title")%>&nbsp;&nbsp;<%=rs("chap")%>:<%=rs("vers")%></b><br>

</span>
</td>
</tr>

<tr style="height:8.0pt"> 
<td width="10" align=center><span>
<center>
<A href="

<%
'Option Explicit
'Response.End 
Response.Buffer=false

Dim letter
Dim letterSQL
Dim str

letterSQL = "SELECT distinct biblewheel_url.book_spoke, biblewheel_url.url "
letterSQL = letterSQL & " FROM biblewheel_url INNER JOIN bible "
letterSQL = letterSQL & " ON biblewheel_url.book_spoke = bible.book_spoke"


    strConn = GetConnectionString()

Set letter = Server.CreateObject("ADODB.Recordset")
    letter.CursorLocation = adUseClient

    letter.Open letterSQL, strConn, adOpenForwardOnly, adLockReadOnly
str = str%>

http://www.biblewheel.com
<%=letter("url")%>

<%

    letter.Close
    set letter = Nothing
%>
" target="_blank">
<IMG SRC="hebrew/<%=RS("book_spoke")%>.jpg" ALT="Book&nbsp;Spoke&nbsp;&nbsp;<%=RS("book_spoke")%>">
</A><br>
<%=RS("book_spoke")%>
</center></span>
</td>

<td width="10" align=center><span>
<IMG SRC="hebrew/<%=RS("chapter_spoke")%>.jpg" ALT="Chapter&nbsp;Spoke&nbsp;&nbsp;<%=RS("chapter_spoke")%>"><br>
<%=RS("chapter_spoke")%></span>
</td>

<td width="10" align=center><span>
<IMG SRC="hebrew/<%=RS("verse_spoke")%>.jpg" ALT="Verse&nbsp;Spoke&nbsp;&nbsp;<%=RS("verse_spoke")%>"><br>
<%=RS("verse_spoke")%></span>
</td>
</tr>
   <%rs.movenext
      ' Exit the loop when reaching the end of the recordset
If rs.EOF Then Exit For 'end if
next
end if%> 
 </table>
<%end if%> 
 

<% rs.Close()%>

Learning of our true origins.

I feel sorry:

http://www.infowars.com/articles/wor...eknowledge.htm

Foreknowledge of A Natural Disaster
Washington was aware that a deadly Tidal Wave was building up in the Indian Ocean
 
Old January 31st, 2005, 08:04 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

OK. I figured it out.

Code:
SQL= "SELECT * "
SQL = SQL & " FROM biblewheel_url INNER JOIN bible "
SQL = SQL & " ON biblewheel_url.book_spoke = bible.book_spoke "
SQL = SQL & " WHERE "

Now biblewheel_url.book_spoke is the primary key. It is numbered 001-022 with different URLs.
http://n.1asphost.com/wheelofgod/tableinhtml.htm
But withinthe biblewheel_url table there are chapter_spoke and verse_spoke fieldnames too numbered 001-022 is it possible that there is a SQL statement which identifies with the URL as shown in the link table:biblewheel_url.


Learning of our true origins.

I feel sorry:

http://www.infowars.com/articles/wor...eknowledge.htm

Foreknowledge of A Natural Disaster
Washington was aware that a deadly Tidal Wave was building up in the Indian Ocean





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Join tables help tdaustin Classic ASP Databases 2 January 11th, 2006 04:57 PM
how to join all records from both tables? yixchen Access 4 January 4th, 2006 01:36 PM
Join Tables tdaustin Classic ASP Basics 1 May 25th, 2004 07:31 AM
Inner Join multiple tables qwprince Classic ASP Databases 5 July 23rd, 2003 02:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.