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!

Page writes out all dB records on load

Status
Not open for further replies.

Webflex

Technical User
Apr 20, 2001
101
GB
Hi

The problem is, when the (html) page loads all records (around 1000) are written out. The html and asp codes are below.

I would like no records to be written out until the search parameters are enetered.

TIA
Webflex



HTML
Code:
<html>
<head>
<title>Employee Directory</title>
<meta http-equiv=&quot;pragma&quot; content=&quot;no-cache&quot;>
<meta http-equiv=&quot;expires&quot; content=&quot;0&quot;> 
<meta http-equiv=&quot;cache-control&quot; content=&quot;no-cache&quot;>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;>
<LINK REL=STYLESHEET HREF=&quot;[URL unfurl="true"]http://blahblah.css&quot;[/URL] TYPE=&quot;text/css&quot;>
</head>
<body>
{Header}
 <table>
  <tr>
   <td valign=&quot;top&quot;>
   <!--BeginFormEmpMonth-->
      <table border=&quot;0&quot; cellspacing=&quot;2&quot; cellpadding=&quot;0&quot;>
        <!--BeginDListEmpMonth-->
        <!--EndDListEmpMonth-->
        <!--BeginEmpMonthNoRecords-->
        <tr> 
          <td colspan=&quot;1&quot; > </td>
        </tr>
        <!--EndEmpMonthNoRecords-->
      </table>
   <!--EndFormEmpMonth-->
   
   </td>
   <td valign=&quot;top&quot;>
   <!--BeginFormSearch--><form method=&quot;GET&quot; action=&quot;{ActionPage}&quot; name=&quot;Search&quot;>
        <table border=&quot;0&quot; cellspacing=&quot;2&quot; cellpadding=&quot;0&quot;>
          <tr> 
            <td align=&quot;center&quot; bgcolor=&quot;#FFBB55&quot; colspan=&quot;2&quot;><a name=&quot;Search&quot;><font style=&quot;font-size: 12pt; color: #FFFFFF; font-family: Arial, Tahoma, Verdana, Helvetica; font-weight: bold&quot;>Search</font></a></td>
          </tr>
          <tr> 
            <td bgcolor=&quot;#FFDD00&quot;><font style=&quot;font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica&quot;>Department</font></td>
            <td > 
              <select name=&quot;dep_id&quot;>
                <option value=&quot;{ID}&quot;>{Value}</option>
              </select>
            </td>
          </tr>
          <tr> 
            <td bgcolor=&quot;#FFDD00&quot;><font style=&quot;font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica&quot;>Name</font></td>
            <td > 
              <input type=&quot;text&quot; name=&quot;name&quot; maxlength=&quot;15&quot; value=&quot;{name}&quot; size=&quot;15&quot;>
            </td>
          </tr>
          <tr> 
            <td bgcolor=&quot;#FFDD00&quot;><font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>Telephone</font></td>
            <td >
              <input type=&quot;text&quot; name=&quot;work_phone&quot; maxlength=&quot;50&quot; value=&quot;{work_phone}&quot; size=&quot;15&quot;>
            </td>
          </tr>
          <tr> 
            <td bgcolor=&quot;#FFDD00&quot;><font style=&quot;font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica&quot;>Initials</font></td>
            <td > 
              <input type=&quot;text&quot; name=&quot;email&quot; maxlength=&quot;50&quot; value=&quot;{email}&quot; size=&quot;15&quot;>
            </td>
          </tr>
          <tr> 
            <td align=&quot;right&quot; colspan=&quot;3&quot;> 
              <input type=&quot;submit&quot; value=&quot;Search&quot;>
            </td>
          </tr>
        </table>
    </form><!--EndFormSearch-->
   
   </td>
  </tr>
 </table>
 <table>
  <tr>
   <td valign=&quot;top&quot;>
   <!--BeginFormGrid--><table border=&quot;0&quot; cellspacing=&quot;2&quot; cellpadding=&quot;0&quot;>
     <tr>
          <td align=&quot;center&quot; bgcolor=&quot;#FFBB55&quot; colspan=&quot;5&quot;><a name=&quot;Grid&quot;><font style=&quot;font-size: 12pt; color: #FFFFFF; font-family: Arial, Tahoma, Verdana, Helvetica; font-weight: bold&quot;>CSOL 
            Directory</font></a></td>
     </tr>
     <tr>
       <td bgcolor=&quot;#000000&quot;><a href=&quot;{FileName}?{FormParams}FormGrid_Sorting=1&FormGrid_Sorted={Form_Sorting}&&quot;><font style=&quot;font-size: 10pt; color: #FFFFFF; font-family: Arial, Tahoma, Verdana, Helvetica; font-weight: bold&quot;>Name</font></a></td>
       <td bgcolor=&quot;#000000&quot;><a href=&quot;{FileName}?{FormParams}FormGrid_Sorting=2&FormGrid_Sorted={Form_Sorting}&&quot;><font style=&quot;font-size: 10pt; color: #FFFFFF; font-family: Arial, Tahoma, Verdana, Helvetica; font-weight: bold&quot;>Title</font></a></td>
       <td bgcolor=&quot;#000000&quot;><a href=&quot;{FileName}?{FormParams}FormGrid_Sorting=3&FormGrid_Sorted={Form_Sorting}&&quot;><font style=&quot;font-size: 10pt; color: #FFFFFF; font-family: Arial, Tahoma, Verdana, Helvetica; font-weight: bold&quot;>Department</font></a></td>
       <td bgcolor=&quot;#000000&quot;><a href=&quot;{FileName}?{FormParams}FormGrid_Sorting=4&FormGrid_Sorted={Form_Sorting}&&quot;><font style=&quot;font-size: 10pt; color: #FFFFFF; font-family: Arial, Tahoma, Verdana, Helvetica; font-weight: bold&quot;>Work Phone</font></a></td>
          <td bgcolor=&quot;#000000&quot;><a href=&quot;{FileName}?{FormParams}FormGrid_Sorting=5&FormGrid_Sorted={Form_Sorting}&&quot;><font style=&quot;font-size: 10pt; color: #FFFFFF; font-family: Arial, Tahoma, Verdana, Helvetica; font-weight: bold&quot;>Initials</font></a></td>
     </tr>
     <!--BeginDListGrid-->
     <tr>
      <td ><a href=&quot;{name_URLLink}?emp_id={Prm_emp_id}&{TransitParams}&quot;><font style=&quot;font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica&quot;>{name}</font></a> </td>
      <td ><font style=&quot;font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica&quot;>{title} </font></td>
      <td ><font style=&quot;font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica&quot;>{dep_id} </font></td>
      <td ><font style=&quot;font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica&quot;>{work_phone} </font></td>
      <td ><font style=&quot;font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica&quot;>{email} </font></td>
     </tr>
     <!--EndDListGrid--> 
     <!--BeginGridNoRecords-->
     <tr><td colspan=&quot;5&quot; ><font style=&quot;font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica&quot;>No records</font></td></tr>
     <!--EndGridNoRecords--> 
    </table>
   <!--EndFormGrid-->
   
   </td>
  </tr>
 </table>


{Footer}

<center>
  <font face=&quot;Arial&quot;><small></small></font>
</center>
</body>
</html>


ASP
Code:
<!-- #INCLUDE FILE=&quot;Common.asp&quot; -->
<%



sFileName = &quot;Default.asp&quot;
sTemplateFileName = &quot;Default.html&quot;




LoadTemplate sAppPath & sTemplateFileName, &quot;main&quot;

LoadTemplate sHeaderFileName, &quot;Header&quot;


SetVar &quot;FileName&quot;, sFileName


Header_Show
Grid_Show
Search_Show
EmpMonth_Show
Parse &quot;Header&quot;, False
Parse &quot;main&quot;, False
Response.write PrintVar(&quot;main&quot;)


'--------------------------------------------------



Sub Grid_Show()
  
  Dim sWhere
  sWhere = &quot;&quot;
  sOrder = &quot;&quot;
  sSQL = &quot;&quot;
  HasParam = false


  SetVar &quot;TransitParams&quot;, &quot;name=&quot; & ToURL(GetParam(&quot;name&quot;)) & &quot;&dep_id=&quot; & ToURL(GetParam(&quot;dep_id&quot;)) & &quot;&email=&quot; & ToURL(GetParam(&quot;email&quot;)) & &quot;&work_phone=&quot; & ToURL(GetParam(&quot;work_phone&quot;)) & &quot;&&quot;
  SetVar &quot;FormParams&quot;, &quot;name=&quot; & ToURL(GetParam(&quot;name&quot;)) & &quot;&dep_id=&quot; & ToURL(GetParam(&quot;dep_id&quot;)) & &quot;&email=&quot; & ToURL(GetParam(&quot;email&quot;)) & &quot;&work_phone=&quot; & ToURL(GetParam(&quot;work_phone&quot;)) & &quot;&&quot;
' Build WHERE statement

  pdep_id = GetParam(&quot;dep_id&quot;)
  if IsNumeric(pdep_id) and not isEmpty(pdep_id) then pdep_id = CLng(pdep_id) else pdep_id = Empty
  if not isEmpty(pdep_id) then
    HasParam = true
    sWhere = sWhere & &quot;e.dep_id=&quot; & pdep_id
  end if
  
  pemail = GetParam(&quot;email&quot;)
  if not isEmpty(pemail) then
    if not (sWhere = &quot;&quot;) then sWhere = sWhere & &quot; and &quot;
    HasParam = true
    sWhere = sWhere & &quot;e.email like '%&quot; & replace(pemail, &quot;'&quot;, &quot;''&quot;) & &quot;%'&quot;
  end if
  
  pname = GetParam(&quot;name&quot;)
  if not isEmpty(pname) then
    if not (sWhere = &quot;&quot;) then sWhere = sWhere & &quot; and &quot;
    HasParam = true
    sWhere = sWhere & &quot;e.name like '%&quot; & replace(pname, &quot;'&quot;, &quot;''&quot;) & &quot;%'&quot;
  end if
  
  pwork_phone = GetParam(&quot;work_phone&quot;)
  if not isEmpty(pwork_phone) then
    if not (sWhere = &quot;&quot;) then sWhere = sWhere & &quot; and &quot;
    HasParam = true
    sWhere = sWhere & &quot;e.work_phone like '%&quot; & replace(work_phone, &quot;'&quot;, &quot;''&quot;) & &quot;%'&quot;
  end if
  
  if HasParam then sWhere = &quot; AND (&quot; & sWhere & &quot;)&quot;
  ' Build ORDER statement
  sOrder = &quot; order by e.name Asc&quot;
  iSort = GetParam(&quot;FormGrid_Sorting&quot;)
  iSorted = GetParam(&quot;FormGrid_Sorted&quot;)
  sDirection = &quot;&quot;
  if IsEmpty(iSort) then
    SetVar &quot;Form_Sorting&quot;, &quot;&quot;
  else
    if iSort = iSorted then 
      SetVar &quot;Form_Sorting&quot;, &quot;&quot;
      sDirection = &quot; DESC&quot;
      sSortParams = &quot;FormGrid_Sorting=&quot; & iSort & &quot;&FormGrid_Sorted=&quot; & iSort & &quot;&&quot;
    else
      SetVar &quot;Form_Sorting&quot;, iSort
      sDirection = &quot; ASC&quot;
      sSortParams = &quot;FormGrid_Sorting=&quot; & iSort & &quot;&FormGrid_Sorted=&quot; & &quot;&&quot;
    end if
    
    if iSort = 1 then sOrder = &quot; order by e.name&quot; & sDirection
    if iSort = 2 then sOrder = &quot; order by e.title&quot; & sDirection
    if iSort = 3 then sOrder = &quot; order by d.name&quot; & sDirection
    if iSort = 4 then sOrder = &quot; order by e.work_phone&quot; & sDirection
    if iSort = 5 then sOrder = &quot; order by e.email&quot; & sDirection
  end if
  

  ' Build full SQL statement
  
  sSQL = &quot;select e.dep_id as e_dep_id, &quot; & _
    &quot;e.email as e_email, &quot; & _
    &quot;e.emp_id as e_emp_id, &quot; & _
    &quot;e.name as e_name, &quot; & _
    &quot;e.title as e_title, &quot; & _
    &quot;e.work_phone as e_work_phone, &quot; & _
    &quot;d.dep_id as d_dep_id, &quot; & _
    &quot;d.name as d_name &quot; & _
    &quot; from emps e, deps d&quot; & _
    &quot; where d.dep_id=e.dep_id  &quot;

  sSQL = sSQL & sWhere & sOrder
  SetVar &quot;SortParams&quot;, sSortParams
  
  ' Open recordset
  openrs rs, sSQL
  if rs.eof then
    ' Recordset is empty
    set rs = nothing
    SetVar &quot;DListGrid&quot;, &quot;&quot;
    Parse &quot;GridNoRecords&quot;, False
    Parse &quot;FormGrid&quot;, False
    exit sub
  end if



  ' Show main table based on recordset
  while not rs.EOF 
    fldname = GetValue(rs, &quot;e_name&quot;)
    fldtitle = GetValue(rs, &quot;e_title&quot;)
    flddep_id = GetValue(rs, &quot;d_name&quot;)
    fldwork_phone = GetValue(rs, &quot;e_work_phone&quot;)
    fldemail = GetValue(rs, &quot;e_email&quot;)
'fldemail=&quot;<a href=mailto:&quot; & fldemail & &quot;>&quot; & fldemail & &quot;</a>&quot;

      SetVar &quot;name&quot;, ToHTML(fldname)
      SetVar &quot;name_URLLink&quot;, &quot;EmpDetail.asp&quot;
      SetVar &quot;Prm_emp_id&quot;, ToURL(GetValue(rs, &quot;e_emp_id&quot;)) 
      SetVar &quot;title&quot;, ToHTML(fldtitle)
      SetVar &quot;dep_id&quot;, ToHTML(flddep_id)
      SetVar &quot;work_phone&quot;, ToHTML(fldwork_phone)
      SetVar &quot;email&quot;, ToHTML(fldemail)

    Parse &quot;DListGrid&quot;, True
    
    rs.MoveNext

  wend


  set rs = nothing
  SetVar &quot;GridNoRecords&quot;, &quot;&quot;
  Parse &quot;FormGrid&quot;, False
  
End Sub



Sub Search_Show()
      
      SetVar &quot;ActionPage&quot;, &quot;Default.asp&quot;

      ' Set variables with search parameters
      
      flddep_id = GetParam(&quot;dep_id&quot;)
      fldname = GetParam(&quot;name&quot;)
      fldemail = GetParam(&quot;email&quot;)
	  fldwork_phone = GetParam(&quot;work_phone&quot;)
      ' Show fields
      

      SetVar &quot;LBdep_id&quot;, &quot;&quot;
      SetVar &quot;ID&quot;, &quot;&quot;
      SetVar &quot;Value&quot;, &quot;All&quot;
      Parse &quot;LBdep_id&quot;, True
      openrs rsdep_id, &quot;select dep_id, name from deps order by 2&quot;
      while not rsdep_id.EOF
        SetVar &quot;ID&quot;, GetValue(rsdep_id, 0) : SetVar &quot;Value&quot;, GetValue(rsdep_id, 1)
        if cstr(GetValue(rsdep_id, 0)) = cstr(flddep_id) then SetVar &quot;Selected&quot;, &quot;SELECTED&quot; else SetVar &quot;Selected&quot;, &quot;&quot;
        Parse &quot;LBdep_id&quot;, True
        rsdep_id.MoveNext
      wend
      set rsdep_id = nothing
    
      SetVar &quot;name&quot;, ToHTML(fldname)
      SetVar &quot;email&quot;, ToHTML(fldemail)
      Parse &quot;FormSearch&quot;, False
End Sub



Sub EmpMonth_Show()
  
  Dim sWhere
  sWhere = &quot;&quot;
  sOrder = &quot;&quot;
  sSQL = &quot;&quot;
  HasParam = false


  SetVar &quot;TransitParams&quot;, &quot;&quot;
  SetVar &quot;FormParams&quot;, &quot;&quot;
' Build WHERE statement

  sWhere = &quot; WHERE manmonth=1&quot;
  

  ' Build full SQL statement
  
  sSQL = &quot;select e.name as e_name, &quot; & _
    &quot;e.picture as e_picture &quot; & _
    &quot; from emps e &quot;

  sSQL = sSQL & sWhere & sOrder
  ' Open recordset
  openrs rs, sSQL
  if rs.eof then
    ' Recordset is empty
    set rs = nothing
    SetVar &quot;DListEmpMonth&quot;, &quot;&quot;
    Parse &quot;EmpMonthNoRecords&quot;, False
    Parse &quot;FormEmpMonth&quot;, False
    exit sub
  end if



  ' Show main table based on recordset
  while not rs.EOF 
    fldpicture = GetValue(rs, &quot;e_picture&quot;)
    fldname = GetValue(rs, &quot;e_name&quot;)
fldpicture=&quot;<img border=0 height=100 width=100 src=images/emps/&quot; & fldpicture & &quot;>&quot;

      SetVar &quot;picture&quot;, fldpicture
      SetVar &quot;name&quot;, ToHTML(fldname)

    Parse &quot;DListEmpMonth&quot;, True
    
    rs.MoveNext

  wend


  set rs = nothing
  SetVar &quot;EmpMonthNoRecords&quot;, &quot;&quot;
  Parse &quot;FormEmpMonth&quot;, False
  
End Sub

%>

<!-- #INCLUDE FILE=&quot;Header.asp&quot; -->
 
In your form set up a hidden field for the trigger.
in the asp code wrap your asp around an If that looks for that trigger to be something.
<%
if request.form(&quot;search&quot;) = &quot;yes&quot; then
'your code here
end if
%>

<form>
<input type=&quot;text&quot;>
<input type=&quot;hidden&quot; name=&quot;search&quot; value=&quot;yes&quot;>
<input type=&quot;submit&quot; value=&quot;search&quot;>
</form>
 
This will cut down on how many records are displayed at once, it will make page numbers at the bottom of the page depending on how many pages / records you want per page / records there are etc..

Hope this helps.


Code:
<% 

get scriptname
ScriptName = Request.ServerVariables(&quot;SCRIPT_NAME&quot;)

'Connect to the included MS Access database
Set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Open &quot;YOUR DB LINE HERE&quot;

'Set how many records per page we want
Const NumPerPage = 30

'Retrieve what page we're currently on
If Request.QueryString(&quot;page&quot;) = &quot;&quot; then
    CurrentPage = 1 'We're on the first page
Else
    CurrentPage = CInt(Request.QueryString(&quot;page&quot;))
End If

'Open our recordset

mySQL = &quot;SELECT * FROM TABLE ORDER BY IDnumber&quot;
rs.Open mySQL, conn, 1, 1   'Opened as Read-Only

If Not rs.EOF Then
 	rs.MoveFirst
	rs.PageSize = NumPerPage
    TotalPages = rs.PageCount

    'Set the absolute (current) page
    rs.AbsolutePage = CurrentPage
End If

Dim Count
%>



'Loop to display data on current page.
Do While Not rs.EOF and Count < rs.PageSize

' Your table / Record fields here:

'Like:

Response.write Username
Response.write email 
Response.write &quot;<p> </p>&quot;  'space out records
'etc..


	rs.MoveNext
	Count = Count + 1
Loop
%>
<%

' Do Page numbers: 

If Not CurrentPage = 1 Then
	Response.Write &quot;<a href='&quot; & ScriptName & &quot;?page=&quot; & CurrentPage - 1 & &quot;'>Prev</a> | &quot; & &quot;</center>&quot;
Else
	Response.Write &quot;Prev | &quot;
End If


%>
                      </font></td>
                    <td><font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;> 
                      <% 'Display NEXT page link, if appropriate
If Not CurrentPage = TotalPages Then
	Response.Write &quot;<a href='&quot; & ScriptName & &quot;?page=&quot; & CurrentPage + 1 & &quot;'>Next</a>&quot;
Else
	Response.Write &quot;Next&quot;
End If

%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top