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!

Multi-page query output 1

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
GB
Hi all

PHP newbie so please be gentle. [wink]

The following script retrieves data and displays the results from a Visual Foxpro table.
Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<table width="75%" border="1" cellspacing="1" cellpadding="1" bgcolor="#FFFFFF">
  <tr bgcolor="#CCFFFF">
    <td height="22"><b>Company</b></td>
    <td height="22"><b>Street</b></td>
    <td height="22"><b>Town</b></td>
  </tr>

<?php

    //connect to the database
    $connectionstring = odbc_connect("vfptable", "", "");

    //SQL query
    $Query = "SELECT company, street, town FROM contacts where 'A' $ company OR 'M' $ company";

    //execute query
    $queryexe = odbc_do($connectionstring, $Query);

    //query database
    while(odbc_fetch_row($queryexe))
    {
    $company = odbc_result($queryexe, 1);
    $street = odbc_result($queryexe, 2);
    $town = odbc_result($queryexe, 3);

    //format results
    print ("<tr>");
    print ("<td>$company</td>");
    print ("<td>$street</td>");
    print ("<td>$town</td>");
    print ("</tr>");
    }

    //disconnect from database
    odbc_close($connectionstring);

    ?>

</table>
</body>
</html>
What modifications are needed to display n records per page and allow navigation to each page?

TIA

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander.com
PDFcommander.co.uk
 
change this line
Code:
for ($cnt=0; $cnt<$numrows; $cnt++){
to
Code:
for ($cnt=0; $cnt<$rowsPerPage; $cnt++){
 
jpadie

Thanks once again for your time and effort.

The ODBC option is certainly simpler than using the OLE DB Provider.

FI, a VFP query similar to the test page would be
Code:
lnRows = 20
lnOffset = 1500
SELECT t2.company, t2.street, t2.town  FROM ;
[tab](SELECT TOP lnRows t1.company, t1.street, t1.town FROM ;
[tab](SELECT TOP lnOffset company, street, town FROM
[tab]C:\server\tables\contacts ;
[tab]ORDER BY company ASC) AS t1 ORDER BY company DESC) ;
[tab]AS t2 WHERE 'A' $ company OR 'M' $ company ;
[tab]ORDER BY company ASC)
Apart from some formatting issues which belong in a separate thread, the job's done. [smile]

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander.com
PDFcommander.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top