Forums
This topic is locked
How to let Record Navigator to work?
05 Oct 2001 08:14:20 xiao biao posted:
I am using phakt+UltraDev+Aoddb1.4+Oracle.When I create a Recordset and using "Insert Recordset Navigation Bar PHP"or using server behavoris->Move to record.The result is move to first,move to next...are not work!How to fix?My code like this:****************************************************************************************
<?php
// Copyright (c) Interakt Online 2001
// www.interakt.ro/
require("./adodb/adodb.inc.php"
require("./Connections/News.php"
?><?php
$Recordset1=$News->Execute("SELECT * FROM CYBER.IMAGECAT" or DIE($News->ErrorMsg());
$Recordset1_numRows=0;
$Recordset1__totalRows=$Recordset1->RecordCount();
?>
<? //***This adding by me.
$rsCount = $News->Execute("SELECT COUNT(*) AS TotRows FROM IMAGECAT" or DIE($Test->ErrorMsg());
$Recordset1__totalRows = $rsCount->Fields("TotRows"
?>
<?php
$Repeat1__numRows = 4;
$Repeat1__index= 0;
$Recordset1_numRows = $Recordset1_numRows + $Repeat1__numRows;
?>
<?php
// *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
// set the record count
$Recordset1_total = $Recordset1->RecordCount();
$Recordset1_total = $rsCount->Fields("TotRows" //***This add by me.
// set the number of rows displayed on this page
if ($Recordset1_numRows < 0) { // if repeat region set to all records
$Recordset1_numRows = $Recordset1_total;
} else if ($Recordset1_numRows == 0) { // if no repeat regions
$Recordset1_numRows = 1;
}
// set the first and last displayed record
$Recordset1_first = 1;
$Recordset1_last = $Recordset1_first + $Recordset1_numRows - 1;
// if we have the correct record count, check the other stats
if ($Recordset1_total != -1) {
$Recordset1_numRows = min($Recordset1_numRows, $Recordset1_total);
$Recordset1_first = min($Recordset1_first, $Recordset1_total);
$Recordset1_last = min($Recordset1_last, $Recordset1_total);
}
?>
<?php $MM_paramName = ""; ?>
<?php
// *** Move To Record and Go To Record: declare variables
$MM_rs = &$Recordset1;
$MM_rsCount = $Recordset1_total;
$MM_size = $Recordset1_numRows;
$MM_uniqueCol = "";
$MM_paramName = "";
$MM_offset = 0;
$MM_atTotal = false;
$MM_paramIsDefined = ($MM_paramName != "" && isset($$MM_paramName));
?>
<?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 >= $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->EOF && ($i < $MM_offset || $MM_offset == -1); $i++) {
$MM_rs->MoveNext();
}
if ($MM_rs->EOF) $MM_offset = $i; // set MM_offset to the last possible record
}
?>
<?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->EOF && ($MM_size < 0 || $i < $MM_offset + $MM_size); $i++) {
$MM_rs->MoveNext();
}
// if we walked off the end of the recordset, set MM_rsCount and MM_size
if ($MM_rs->EOF) {
$MM_rsCount = $i;
if ($MM_size < 0 || $MM_size > $MM_rsCount) $MM_size = $MM_rsCount;
}
// if we walked off the end, set the offset based on page size
if ($MM_rs->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->MoveFirst();
// move the cursor to the selected record
for ($i=0; !$MM_rs->EOF && $i < $MM_offset; $i++) {
$MM_rs->MoveNext();
}
}
?>
<?php
// *** Move To Record: update recordset stats
// set the first and last displayed record
$Recordset1_first = $MM_offset + 1;
$Recordset1_last = $MM_offset + $MM_size;
if ($MM_rsCount != -1) {
$Recordset1_first = $Recordset1_first<$MM_rsCount?$Recordset1_first:$MM_rsCount;
$Recordset1_last = $Recordset1_last<$MM_rsCount?$Recordset1_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 >= $MM_rsCount);
?>
<?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) > 0) $MM_keepBoth = substr($MM_keepBoth, 1);
if (strlen($MM_keepURL) > 0) $MM_keepURL = substr($MM_keepURL, 1);
if (strlen($MM_keepForm) > 0) $MM_keepForm = substr($MM_keepForm, 1);
?>
<?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 > 1) {
$MM_moveParam = "offset";
if (strlen($MM_keepMove)> 0) {
$params = explode("&", $MM_keepMove);
$MM_keepMove = "";
for ($i=0; $i < sizeof($params); $i++) {
list($nextItem) = explode("=", $params[$i]);
if (strtolower($nextItem) != $MM_moveParam) {
$MM_keepMove.="&".$params[$i];
}
}
if (strlen($MM_keepMove) > 0) $MM_keepMove = substr($MM_keepMove, 1);
}
}
// set the strings for the move to links
if (strlen($MM_keepMove) > 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));
?>
<html>
<head>
<title>Test Navigator</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<table width="200" border="1" align="center">
<?php while (($Repeat1__numRows-- != 0) && (!$Recordset1->EOF))
{
?>
<tr>
<td>
<?php echo $Recordset1->Fields("CAT_ID"?>
</td>
<td>
<?php echo $Recordset1->Fields("CAT_TITLE"?>
</td>
</tr>
<?php
$Repeat1__index++;
$Recordset1->MoveNext();
}
?>
</table>
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center">
<?php if ($MM_offset != 0) { ?>
<a href="<?php echo $MM_moveFirst?>">First</a>
<?php } // end $MM_offset != 0 ?>
</td>
<td width="31%" align="center">
<?php if ($MM_offset != 0) { ?>
<a href="<?php echo $MM_movePrev?>">Previous</a>
<?php } // end $MM_offset != 0 ?>
</td>
<td width="23%" align="center">
<?php if (!$MM_atTotal) { ?>
<a href="<?php echo $MM_moveNext?>">Next</a>
<?php } // end !$MM_atTotal ?>
</td>
<td width="23%" align="center">
<?php if (!$MM_atTotal) { ?>
<a href="<?php echo $MM_moveLast?>">Last</a>
<?php } // end !$MM_atTotal ?>
</td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>
<?php
$Recordset1->Close();
?>
Replies
Replied 05 Oct 2001 15:15:26
05 Oct 2001 15:15:26 Tim Green replied:
The problem is in the fact that the RecordCount() function of ADODB does not work with ORACLE.
You will need to go through your source code, and replace all instances of $Recordset1->RecordCount() for $rsCount->Fields("TotRows"
Once you have done that it should all work just fine!
Hope this helps.
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>
You will need to go through your source code, and replace all instances of $Recordset1->RecordCount() for $rsCount->Fields("TotRows"
Once you have done that it should all work just fine!
Hope this helps.
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>
Replied 05 Oct 2001 17:59:42
05 Oct 2001 17:59:42 xiao biao replied:
I had replace all instances of $Recordset1->RecordCount() for $rsCount->Fields("TotRows"
,but the navigation bar not work continue.How to do right?
,but the navigation bar not work continue.How to do right?
Replied 07 Oct 2001 01:40:23
07 Oct 2001 01:40:23 Tim Green replied:
If you replaced all of the $Recordset1->RecordCount() entries in your code (which you hadn't done in the code you posted) then it should work.
If it doesn't it could well be that Oracle doesn't support the recordset movement using MoveTo,MoveNext,MoveFirst,MoveLast,MovePrev functions. If this is the case then there's not a lot I can do.
The best place to check to see if Oracle does support such functionality, is the ADODB homepage at php.weblogs.com/ADODB
If you have no luck with my above comment or by visiting the webpage above, then I can't help you any further. Sorry.
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>
If it doesn't it could well be that Oracle doesn't support the recordset movement using MoveTo,MoveNext,MoveFirst,MoveLast,MovePrev functions. If this is the case then there's not a lot I can do.
The best place to check to see if Oracle does support such functionality, is the ADODB homepage at php.weblogs.com/ADODB
If you have no luck with my above comment or by visiting the webpage above, then I can't help you any further. Sorry.
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>