paging problem

7 posts by 2 authors in: Forums > CMS Builder
Last Post: January 16, 2009   (RSS)

I have a strange paging problem. I have a viewer on a newsDetail page that displays the news item then the comments that are linked to news items by the num field of the news table. There are actually four viewers on this page (the other two are not important).

The problem I am having is with paging of the comments.

Example: if I page to the second comments page the page displays the news item and page 2 of the comments just fine. However, if I page to page 3 or back to page 1, even though the url is correct the wrong news item page displays?

I am using the getNumberFromEndOfUrl() function to grab the num value from the news item and then using it in the where clause of the comments viewer. The strange part of this is that the url on the paging link and in the address bar are correct but it goes to the wrong news item.

Any ideas as to why this happens?

Re: [jsantari] paging problem

By Dave - January 13, 2009

Hi jsantari,

Do you have an example url where we can see the issue?

My first guess is that when you link to page 1, or 3 of the comments the url looks like this: yourViewer.php?page=3 and getNumberFromEndOfUrl() is mistakenly getting that 3 as the record number.

Some solutions would be to show the comments in an iframe so their url could change without changing the content on the page. Or passing the record num as num=123 and pulling it into the where like this:

'where' => "num = '" .mysql_real_escape_string(@$_REQUEST['num']). "' ",

Hope that helps, let me know if one of those solutions will work for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] paging problem

Code is only running on my dev server so I can't show you a link. However, your suggestion points out the problem which is related to how the getNumberFromEndOfUrl() function works. It does exactly what it says, gets the number from the end of the url which as you suggested is the value after page=3. The solution to the problem was a simple change to the getNumberFromEndOfUrl() so that it first removes any data from the url after the =& that appears on a link. After making that change it works just fine and as expected. If doing this won't cause any problems then maybe the function could be modified for future versions?

Re: [Dave] paging problem

In getNumberFromEndOfUrl() function I added these two lines right before the if (preg_match...) statement:

$url = explode('=&',$urlData);
$urlData = $url[0];

It makes $urlData always contain just the url we want to strip the num off of.

Jim

Re: [jsantari] paging problem

By Dave - January 15, 2009

Hi Jim,

Interesting. We won't be able to add that to viewer_functions.php because some people rely on the currently functionality of getting the number from the end of the url (instead of the beginning of the url).

To make your version upgrade proof I'd suggest creating a copy of the function called getNumberFromUrl() or something else and calling that one.

Hope that helps. Let me know if you need anything else.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] paging problem

Hi Dave,

I have created a second function in my own lib file as you suggested and it works fine.

Thanks,
Jim