Forums

PHP

This topic is locked

Ultradev and PHP Phakt Problem

Posted 15 Dec 2001 18:08:49
1
has voted
15 Dec 2001 18:08:49 Worathep Paiboonrattanakorn posted:
I am using Ultradev and PHP Phakt extension.
I want to build the navigation page by using
"move to prev record" and "move to next record" in the server behaviors. My problem is the page that I build up display the second record instead of first record and when I link to next record it will display in the forth record instead of the second record. Please help me what wrong happen and what can I do.(My data base is MSAccess.)



Replies

Replied 16 Dec 2001 01:27:55
16 Dec 2001 01:27:55 Tim Green replied:
Please upload your page to your website (or wherever) and post the URL so we can see what is going on.

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 16 Dec 2001 19:17:08
16 Dec 2001 19:17:08 Worathep Paiboonrattanakorn replied:
Hi Tim,

Sorry for my late. My location page is

www.astronlogic.com/view.php

There are 5 differnt records in my DB.
When you load this page, it display the wrong result-&gt; it point to second record instead of first record and error for every record.

Thank you.



Replied 17 Dec 2001 11:49:41
17 Dec 2001 11:49:41 Tim Green replied:
Sorry, but I'm getting 404 errors when I try to access that page.

Could you upload it again? Also when you do that upload a txt version of the same page, so I can see the source code.

Thanks.

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 17 Dec 2001 18:32:33
17 Dec 2001 18:32:33 Worathep Paiboonrattanakorn replied:
Hi Tom,
I already upload that page again. <img src=../images/dmxzone/forum/icon_smile_shock.gif border=0 align=middle>

Here is my source code
/////////////////////////////////////////////

&lt;?php


// Copyright (c) Interakt Online 2001
// www.interakt.ro/

require("./adodb/adodb.inc.php";
require("./Connections/AstronConnect.php";
?&gt;&lt;?php
$Recordset1=$AstronConnect-&gt;Execute("SELECT * FROM Chips" or DIE($AstronConnect-&gt;ErrorMsg());
$Recordset1_numRows=0;
$Recordset1__totalRows=$Recordset1-&gt;RecordCount();
?&gt;&lt;?php
// *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

// set the record count
$Recordset1_total = $Recordset1-&gt;RecordCount();

// set the number of rows displayed on this page
if ($Recordset1_numRows &lt; 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);
}
?&gt;&lt;?php $MM_paramName = ""; ?&gt;&lt;?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));
?&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
$Recordset1_first = $MM_offset + 1;
$Recordset1_last = $MM_offset + $MM_size;
if ($MM_rsCount != -1) {
$Recordset1_first = $Recordset1_first&lt;$MM_rsCount?$Recordset1_first:$MM_rsCount;
$Recordset1_last = $Recordset1_last&lt;$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 &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;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Un title page&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=windows-874"&gt;
&lt;style type="text/css"&gt;
&lt;!--
body { margin: 0px 0px; padding: 0px 0px}
a:link { color: #005CA2; text-decoration: none}
a:visited { color: #005CA2; text-decoration: none}
a:active { color: #0099FF; text-decoration: underline}
a:hover { color: #0099FF; text-decoration: underline}
--&gt;
&lt;/style&gt;
&lt;/head&gt;
&lt;body bgcolor="#FFFFFF"&gt;
&lt;table width="75%" border="1"&gt;
&lt;tr&gt;
&lt;td&gt;ID&lt;/td&gt;
&lt;td&gt;Name&lt;/td&gt;
&lt;td&gt;Cost&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;?php echo $Recordset1-&gt;Fields("ID"?&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;?php echo $Recordset1-&gt;Fields("Chip_Number"?&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;?php echo $Recordset1-&gt;Fields("Cost"?&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;
&lt;table border="0" width="50%" align="center"&gt;
&lt;tr&gt;
&lt;td width="23%" align="center"&gt;
&lt;?php if ($MM_offset != 0) { ?&gt;
&lt;a href="&lt;?php echo $MM_moveFirst?&gt;"&gt;&lt;img src="First.gif" border=0&gt;&lt;/a&gt;
&lt;?php } // end $MM_offset != 0 ?&gt;
&lt;/td&gt;
&lt;td width="31%" align="center"&gt;
&lt;?php if ($MM_offset != 0) { ?&gt;
&lt;a href="&lt;?php echo $MM_movePrev?&gt;"&gt;&lt;img src="Previous.gif" border=0&gt;&lt;/a&gt;
&lt;?php } // end $MM_offset != 0 ?&gt;
&lt;/td&gt;
&lt;td width="23%" align="center"&gt;
&lt;?php if (!$MM_atTotal) { ?&gt;
&lt;a href="&lt;?php echo $MM_moveNext?&gt;"&gt;&lt;img src="Next.gif" border=0&gt;&lt;/a&gt;
&lt;?php } // end !$MM_atTotal ?&gt;
&lt;/td&gt;
&lt;td width="23%" align="center"&gt;
&lt;?php if (!$MM_atTotal) { ?&gt;
&lt;a href="&lt;?php echo $MM_moveLast?&gt;"&gt;&lt;img src="Last.gif" border=0&gt;&lt;/a&gt;
&lt;?php } // end !$MM_atTotal ?&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php
$Recordset1-&gt;Close();
?&gt;



Thank you.


Replied 18 Dec 2001 00:25:59
18 Dec 2001 00:25:59 Tim Green replied:
Thanks for the post, I will look at the page now.

I meant that you post the source code as a text file on your webserver, as posting source code like this on a thread makes it illegible and visitors to the thread find it difficult going. Please remember that in the future <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>

Oh! And the name is <b>Tim</b> <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

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 18 Dec 2001 00:29:01
18 Dec 2001 00:29:01 Tim Green replied:
You really should study the UltraDev documentation (it still applies, even if it doesn't cover PHP).

You have not applied a repeat region to the page. For this reason you will only ever get one record per page in the way that you have done.

Before posting in the future please remember to follow all the guidelines as laid out in the forum FAQ (the link for which you will find in my signature).

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 19 Dec 2001 00:52:18
19 Dec 2001 00:52:18 Tim Green replied:
Thread unlocked due to my misunderstanding of the problem.... my apologies.

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 19 Dec 2001 19:38:50
19 Dec 2001 19:38:50 Worathep Paiboonrattanakorn replied:
Hi Tim,
Thank you for the unlock my topic. I'm apologize again for my English usage.
In the future, I will try to be more clear about my problem.


At this time I already find the cause of my problem.<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle> It happen because the adodb is not support the RecordCount() function when we use the MSAccess Database, (for MSAccess RecordCount will return -1).Then the result of MoveToRecord server behavior will be failed.

Thank you.

Replied 20 Dec 2001 00:42:32
20 Dec 2001 00:42:32 Tim Green replied:
Thanks for letting us know. I knew this had been an issue with past versions of ADODB, and thought that they had a work around for it. Obviously I was wrong.

Cheers!

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 20 Dec 2001 10:36:06
20 Dec 2001 10:36:06 Tim Green replied:
I think I may have come up with a fix for this issue, check out this thread:-

www.udzone.com/forum/topic.asp?TOPIC_ID=13226&CAT_ID=5&FORUM_ID=67&Forum_Title=PHP&Topic_Title=Nothing+Working%21%21

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 21 Dec 2001 18:42:16
21 Dec 2001 18:42:16 Worathep Paiboonrattanakorn replied:
Hi Tim,
Thank very very much for your help. <img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>
I can solve all my problem from your technique.

Mery Christmas and Happy New Year for you

Regards,
khunthep


Reply to this topic