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

SelectLimit with ORDER BY not working with Access Database

Status
Not open for further replies.

NateUNI

MIS
Jan 3, 2002
132
US
I am working with a Access Database and when I run the following code, it returns all records, instead of just the first 20.

<?php
//Connection statement
require_once('Connections/STATS.php');

// begin Recordset
$maxRows_Recordset1 = 20;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
$MMsort__Recordset1 = 'asc';
if (isset($_GET['ord'])) {
$MMsort__Recordset1 = $_GET['ord'];
}
$MMname__Recordset1 = 'STATUS';
if (isset($_GET['str'])) {
$MMname__Recordset1 = $_GET['str'];
}
$query_Recordset1 = sprintf(&quot;SELECT * FROM BugTracking ORDER BY %s %s&quot;, $MMname__Recordset1,$MMsort__Recordset1);

$Recordset1 = $STATS->SelectLimit($query_Recordset1, $maxRows_Recordset1, $startRow_Recordset1) or die($STATS->ErrorMsg());

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = $STATS->SelectLimit($query_Recordset1) or die($STATS->ErrorMsg());
$totalRows_Recordset1 = $all_Recordset1->RecordCount();
}

$totalPages_Recordset1 = (int)(($totalRows_Recordset1-1)/$maxRows_Recordset1);

// end Recordset
//PHP ADODB document - made with PHAkt 2.6.2?>

However if I run the following code without the ORDER BY clause it works fine.

<?php
//Connection statement
require_once('Connections/STATS.php');

// begin Recordset
$maxRows_Recordset1 = 20;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
$MMsort__Recordset1 = 'asc';
if (isset($_GET['ord'])) {
$MMsort__Recordset1 = $_GET['ord'];
}
$MMname__Recordset1 = 'STATUS';
if (isset($_GET['str'])) {
$MMname__Recordset1 = $_GET['str'];
}
//$query_Recordset1 = sprintf(&quot;SELECT * FROM BugTracking ORDER BY %s %s&quot;, $MMname__Recordset1,$MMsort__Recordset1);
$query_Recordset1 = sprintf(&quot;SELECT * FROM BugTracking&quot;);

$Recordset1 = $STATS->SelectLimit($query_Recordset1, $maxRows_Recordset1, $startRow_Recordset1) or die($STATS->ErrorMsg());

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = $STATS->SelectLimit($query_Recordset1) or die($STATS->ErrorMsg());
$totalRows_Recordset1 = $all_Recordset1->RecordCount();
}

$totalPages_Recordset1 = (int)(($totalRows_Recordset1-1)/$maxRows_Recordset1);

// end Recordset
//PHP ADODB document - made with PHAkt 2.6.2?>

Any ideas on what I can do?? Thanks!!
 
Hard to say.

It looks like SetLimit is a class method that is a wrapper for lower-level database functions. Maybe there's a bug in that class.

Assuming that $STAT is defined in the file stats.php, what is the provenance of the class?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top