Forums

PHP

This topic is locked

Recordset Navigation skips ahead (MS Access)

Posted 26 Jan 2002 10:47:49
1
has voted
26 Jan 2002 10:47:49 Jack McNeely posted:
Environment:
NT 4.0, IIS 4, PHP 4.1.1, UltraDev 4, PHAkt 1.1.3, aodbc 1.65
Access database configured as system DSN, no sql server

I'm seeing something that I don't understand when I insert a Recordset
Navigation Bar -- the "?offset=whatever" links seem to lose sync with the
record IDs in the database.

I make a page with a recordset that includes all the records and that
does not have a Repeat region, so that displaying the page in a browser
shows just the first record. Then I use Insert > Live Object to insert a
Recordset Navigation Bar. But when I display the page in a browser, it
skips the first record and displays record ID number 2. When I hit the Next
link, it displays record ID number 4 (skipping No. 3).

If I put a Repeat region in a page, to display five records at a time, and
display the page in a browser, it shows the first five records. But then when
I add a Recordset Navigation Bar and display the page in a browser, it skips
the first five records and starts with record ID no. 6 -- it displays 6 thru 10.
Then when I hit the Next link, it skips five records and displays records 16
thru 20.

Why, oh, why? Has anyone encountered this skipping syndrome and perhaps
can say what I am doing wrong?

In php.ini:
register_globals = On
magic_quotes_gpc = On
magic_quotes_runtime = On
magic_quotes_sybase = On


Replies

Replied 26 Jan 2002 19:44:29
26 Jan 2002 19:44:29 Jack McNeely replied:
Here is the generated code, with the Repeat region set to 5:
<pre id=code><font face=courier size=2 id=code>
&lt;?php
require("./../Connections/connRKcmty.php";
?&gt;&lt;?php
$rsCmty=$connRKcmty-&gt;Execute("SELECT * FROM community" or DIE($connRKcmty-&gt;ErrorMsg());
$rsCmty_numRows=0;
$rsCmty__totalRows=$rsCmty-&gt;RecordCount();
?&gt;&lt;?php
$Repeat1__numRows = 5;
$Repeat1__index= 0;
$rsCmty_numRows = $rsCmty_numRows + $Repeat1__numRows;
?&gt;&lt;?php
// *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

// set the record count
$rsCmty_total = $rsCmty-&gt;RecordCount();

// set the number of rows displayed on this page
if ($rsCmty_numRows &lt; 0) { // if repeat region set to all records
$rsCmty_numRows = $rsCmty_total;
} else if ($rsCmty_numRows == 0) { // if no repeat regions
$rsCmty_numRows = 1;
}

// set the first and last displayed record
$rsCmty_first = 1;
$rsCmty_last = $rsCmty_first + $rsCmty_numRows - 1;

// if we have the correct record count, check the other stats
if ($rsCmty_total != -1) {
$rsCmty_numRows = min($rsCmty_numRows, $rsCmty_total);
$rsCmty_first = min($rsCmty_first, $rsCmty_total);
$rsCmty_last = min($rsCmty_last, $rsCmty_total);
}
?&gt;&lt;?php $MM_paramName = ""; ?&gt;&lt;?php
// *** Move To Record and Go To Record: declare variables

$MM_rs = &$rsCmty;
$MM_rsCount = $rsCmty_total;
$MM_size = $rsCmty_numRows;
$MM_uniqueCol = "";
$MM_paramName = "";
$MM_offset = 0;
$MM_atTotal = false;
$MM_paramIsDefined = ($MM_paramName != "" && isset($$MM_paramName));
?&gt;&lt;?php
// *** Move To Record: handle 'index' or 'offset' parameter

if (!$MM_paramIsDefined && $MM_rsCount != 0) {

// use index parameter if defined, otherwise use offset parameter
if(isset($index)){
$r = $index;
} else {
if(isset($offset)) {
$r = $offset;
} else {
$r = 0;
}
}
$MM_offset = $r;

// if we have a record count, check if we are past the end of the recordset
if ($MM_rsCount != -1) {
if ($MM_offset &gt;= $MM_rsCount || $MM_offset == -1) { // past end or move last
if (($MM_rsCount % $MM_size) != 0) { // last page not a full repeat region
$MM_offset = $MM_rsCount - ($MM_rsCount % $MM_size);
}
else {
$MM_offset = $MM_rsCount - $MM_size;
}
}
}

// move the cursor to the selected record
for ($i=0;!$MM_rs-&gt;EOF && ($i &lt; $MM_offset || $MM_offset == -1); $i++) {
$MM_rs-&gt;MoveNext();
}
if ($MM_rs-&gt;EOF) $MM_offset = $i; // set MM_offset to the last possible record
}
?&gt;&lt;?php
// *** Move To Record: if we dont know the record count, check the display range

if ($MM_rsCount == -1) {

// walk to the end of the display range for this page
for ($i=$MM_offset; !$MM_rs-&gt;EOF && ($MM_size &lt; 0 || $i &lt; $MM_offset + $MM_size); $i++) {
$MM_rs-&gt;MoveNext();
}

// if we walked off the end of the recordset, set MM_rsCount and MM_size
if ($MM_rs-&gt;EOF) {
$MM_rsCount = $i;
if ($MM_size &lt; 0 || $MM_size &gt; $MM_rsCount) $MM_size = $MM_rsCount;
}

// if we walked off the end, set the offset based on page size
if ($MM_rs-&gt;EOF && !$MM_paramIsDefined) {
if (($MM_rsCount % $MM_size) != 0) { // last page not a full repeat region
$MM_offset = $MM_rsCount - ($MM_rsCount % $MM_size);
} else {
$MM_offset = $MM_rsCount - $MM_size;
}
}

// reset the cursor to the beginning
$MM_rs-&gt;MoveFirst();

// move the cursor to the selected record
for ($i=0; !$MM_rs-&gt;EOF && $i &lt; $MM_offset; $i++) {
$MM_rs-&gt;MoveNext();
}
}
?&gt;&lt;?php
// *** Move To Record: update recordset stats

// set the first and last displayed record
$rsCmty_first = $MM_offset + 1;
$rsCmty_last = $MM_offset + $MM_size;
if ($MM_rsCount != -1) {
$rsCmty_first = $rsCmty_first&lt;$MM_rsCount?$rsCmty_first:$MM_rsCount;
$rsCmty_last = $rsCmty_last&lt;$MM_rsCount?$rsCmty_last:$MM_rsCount;
}

// set the boolean used by hide region to check if we are on the last record
$MM_atTotal = ($MM_rsCount != -1 && $MM_offset + $MM_size &gt;= $MM_rsCount);
?&gt;&lt;?php
// *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

// create the list of parameters which should not be maintained
$MM_removeList = "&index=";
if ($MM_paramName != "" $MM_removeList .= "&".strtolower($MM_paramName)."=";
$MM_keepURL="";
$MM_keepForm="";
$MM_keepBoth="";
$MM_keepNone="";

// add the URL parameters to the MM_keepURL string
reset ($HTTP_GET_VARS);
while (list ($key, $val) = each ($HTTP_GET_VARS)) {
$nextItem = "&".strtolower($key)."=";
if (!stristr($MM_removeList, $nextItem)) {
$MM_keepURL .= "&".$key."=".urlencode($val);
}
}

// add the URL parameters to the MM_keepURL string
if(isset($HTTP_POST_VARS)){
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
$nextItem = "&".strtolower($key)."=";
if (!stristr($MM_removeList, $nextItem)) {
$MM_keepForm .= "&".$key."=".urlencode($val);
}
}
}

// create the Form + URL string and remove the intial '&' from each of the strings
$MM_keepBoth = $MM_keepURL."&".$MM_keepForm;
if (strlen($MM_keepBoth) &gt; 0) $MM_keepBoth = substr($MM_keepBoth, 1);
if (strlen($MM_keepURL) &gt; 0) $MM_keepURL = substr($MM_keepURL, 1);
if (strlen($MM_keepForm) &gt; 0) $MM_keepForm = substr($MM_keepForm, 1);
?&gt;&lt;?php
// *** Move To Record: set the strings for the first, last, next, and previous links

$MM_moveFirst="";
$MM_moveLast="";
$MM_moveNext="";
$MM_movePrev="";
$MM_keepMove = $MM_keepBoth; // keep both Form and URL parameters for moves
$MM_moveParam = "index";

// if the page has a repeated region, remove 'offset' from the maintained parameters
if ($MM_size &gt; 1) {
$MM_moveParam = "offset";
if (strlen($MM_keepMove)&gt; 0) {
$params = explode("&", $MM_keepMove);
$MM_keepMove = "";
for ($i=0; $i &lt; sizeof($params); $i++) {
list($nextItem) = explode("=", $params[$i]);
if (strtolower($nextItem) != $MM_moveParam) {
$MM_keepMove.="&".$params[$i];
}
}
if (strlen($MM_keepMove) &gt; 0) $MM_keepMove = substr($MM_keepMove, 1);
}
}

// set the strings for the move to links
if (strlen($MM_keepMove) &gt; 0) $MM_keepMove.="&";
$urlStr = $PHP_SELF."?".$MM_keepMove.$MM_moveParam."=";
$MM_moveFirst = $urlStr."0";
$MM_moveLast = $urlStr."-1";
$MM_moveNext = $urlStr.($MM_offset + $MM_size);
$MM_movePrev = $urlStr.(max($MM_offset - $MM_size,0));
?&gt;
</font id=code></pre id=code>

Replied 28 Jan 2002 13:41:02
28 Jan 2002 13:41:02 Tim Green replied:
Issues with navigation while using Access (or any other ODBC connection) come up time and time again.

This issue is caused because of the way that Access reports back it's current record status (in that it really doesn't). It's an issue with ADODB, and until ADODB (www.phpweblogs.com/ADODB) manage to find a way of simulating it there will always be a problem.

Unfortunately that means that there is no easy answer to your problem.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>

Reply to this topic