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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database query question

Status
Not open for further replies.

nwt002

MIS
Jun 16, 2005
58
US
Hello,

I posted something similar to this earlier, but now my question has changed a little. I am using Frontpage and have used its 'Database Interface Wizard' to create a .asp page that displays database results and also a page for me to edit my database from the web. The database that it created for me is an Access database and will just contain a list of quotes. The two columns in the DB are 'Key' which is autonumbered, and 'quote' which is just text. Whenever I find quotes that I like I will be adding them to the database, so the number of records will always be changing. I want the results page to display only 1 random record everytime the screen is refreshed. Another user has given me this code, when I had this posted in the Access forum:
Code:
SELECT TOP 1 key, quote 
FROM Results, (Select Min(key) as MinValue FROM Results) TMin 
WHERE Key>=(((Select Max(key) FROM Results) - TMin.MinValue) * Rnd + TMin.MinValue)

When I rerun this query within Access it returns a different record almost everytime, so I know that the query works. The issue I am having now is that when I try and query on the 'results webpage', it displays the same record each time I refresh the page, even after I clear the cache. I was wondering if there may be any script that I might need to add to the page to rerun the query everytime the page is refreshed. I would appreciate any suggestions you may have. I don't know much about scripting, so the more info the better, and if you need anymore info from me just let me know. :) Thanks!

Below is the HTML and script that the Frontpage Wizard created for the results page with the query that I listed above in case it anyone needs to see it:
Code:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Results -- View</title>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>

<body bgcolor="#FFFFFF">

<table width="100%" align=left>
  <tr>
    <td width="50%">
	  <b><font size=+3 color="#000080"> Results Page </font></b>
	</td>
    <td width="50%" align=right>
      <table>
        <tr>
          <td>
		Results Page
| <a href="editor/database_editor.asp" target="_top">Database Editor</a>
          </td>
        </tr>
      </table>
	</td>
  </tr>
</table>


<p>
<br clear="all">
<hr>
<p>

<table width="100%" border="1" height="46">
  <thead>
    <tr>
      <td height="1"><b>key</b></td>
      <td height="1"><b>quote</b></td>
    </tr>
  </thead>
  <tbody>
    <!--webbot bot="DatabaseRegionStart" s-columnnames="key,quote" s-columntypes="3,202" s-dataconnection="quotes" b-tableformat="TRUE" b-menuformat="FALSE" s-menuchoice="key" s-menuvalue="key" b-tableborder="TRUE" b-tableexpand="TRUE" b-tableheader="TRUE" b-listlabels="TRUE" b-listseparator="TRUE" i-listformat="0" b-makeform="TRUE" s-recordsource s-displaycolumns="key,quote" s-criteria s-order s-sql="SELECT TOP 1 key, quote &lt;br&gt;FROM Results, (Select Min(key) as MinValue FROM Results) TMin &lt;br&gt;WHERE Key&amp;gt;=(((Select Max(key) FROM Results) - TMin.MinValue) * Rnd + TMin.MinValue)" b-procedure="FALSE" clientside suggestedext="asp" s-defaultfields s-norecordsfound="No records returned." i-maxrecords="0" i-groupsize="0" botid="0" u-dblib="../../_fpclass/fpdblib.inc" u-dbrgn1="../../_fpclass/fpdbrgn1.inc" u-dbrgn2="../../_fpclass/fpdbrgn2.inc" tag="TBODY" preview="&lt;tr&gt;&lt;td colspan=64 bgcolor=&quot;#FFFF00&quot; align=&quot;left&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;This is the start of a Database Results region.&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;" b-WasTableFormat="TRUE" startspan --><!--#include file="../../_fpclass/fpdblib.inc"-->
<% if 0 then %>
<SCRIPT Language="JavaScript">
document.write("<div style='background: yellow; color: black;'>The Database Results component on this page is unable to display database content. The page must have a filename ending in '.asp', and the web must be hosted on a server that supports Active Server Pages.</div>");
</SCRIPT>
<% end if %>
<%
fp_sQry="SELECT TOP 1 key, quote  FROM Results, (Select Min(key) as MinValue FROM Results) TMin  WHERE Key>=(((Select Max(key) FROM Results) - TMin.MinValue) * Rnd + TMin.MinValue)"
fp_sDefault=""
fp_sNoRecords="<tr><td colspan=2 align=left width=""100%"">No records returned.</td></tr>"
fp_sDataConn="quotes"
fp_iMaxRecords=0
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=True
fp_fMenuFormat=False
fp_sMenuChoice="key"
fp_sMenuValue="key"
fp_iDisplayCols=2
fp_fCustomQuery=True
BOTID=0
fp_iRegion=BOTID
%>
<!--#include file="../../_fpclass/fpdbrgn1.inc"-->
<!--webbot bot="DatabaseRegionStart" endspan i-checksum="47763" --><tr>
      <td height="8">
      <!--webbot bot="DatabaseResultColumn" s-columnnames="key,quote" s-column="key" b-tableformat="TRUE" b-hashtml="FALSE" b-makelink="FALSE" clientside b-MenuFormat preview="&lt;font size=&quot;-1&quot;&gt;&amp;lt;&amp;lt;&lt;/font&gt;key&lt;font size=&quot;-1&quot;&gt;&amp;gt;&amp;gt;&lt;/font&gt;" startspan --><%=FP_FieldVal(fp_rs,"key")%><!--webbot bot="DatabaseResultColumn" endspan i-checksum="4558" --></td>
      <td height="8">
      <!--webbot bot="DatabaseResultColumn" s-columnnames="key,quote" s-column="quote" b-tableformat="TRUE" b-hashtml="FALSE" b-makelink="FALSE" clientside b-MenuFormat preview="&lt;font size=&quot;-1&quot;&gt;&amp;lt;&amp;lt;&lt;/font&gt;quote&lt;font size=&quot;-1&quot;&gt;&amp;gt;&amp;gt;&lt;/font&gt;" startspan --><%=FP_FieldVal(fp_rs,"quote")%><!--webbot bot="DatabaseResultColumn" endspan i-checksum="12176" --></td>
    </tr>
    <!--webbot bot="DatabaseRegionEnd" b-tableformat="TRUE" b-menuformat="FALSE" u-dbrgn2="../../_fpclass/fpdbrgn2.inc" i-groupsize="0" clientside tag="TBODY" preview="&lt;tr&gt;&lt;td colspan=64 bgcolor=&quot;#FFFF00&quot; align=&quot;left&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;This is the end of a Database Results region.&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;" startspan --><!--#include file="../../_fpclass/fpdbrgn2.inc"-->
<!--webbot bot="DatabaseRegionEnd" endspan i-checksum="65064" --></tbody>
</table>
<p>&nbsp;</p>



</body>

</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top