vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Problem with pagination URL (https://vborg.vbsupport.ru/showthread.php?t=314940)

TheAdminMarket 10-17-2014 04:08 PM

Problem with pagination URL
 
Hello all,

Does anybody know what appears in the URL when one parameter is array? eg:
&genders=Array&roles=Array
is correct?

Actually it must be correct as the pagination works just fine (I mean navigating between the pages), but I can't get the values for another action that I want.

Testing the 1st page with:
Code:

if (is_array($genders))
{
        echo "1";
        print_r($genders);
}

I'm getting: 1Array ( [0] => 1 [1] => 2 ) which is correct. But moving to any other page I'm getting: 1Array ( ) . Empty array.

The most important parts of the code before are:
Code:

$vbulletin->input->clean_array_gpc('r', array(
'homeform' => TYPE_INT,
'genders' => TYPE_ARRAY_INT,
'roles' => TYPE_ARRAY_INT,
....
));
$genders = $vbulletin->GPC['genders'];
$roles = $vbulletin->GPC['roles'];
// Below I've the code for counting the amount of rows etc etc.
..........
// Storing the values to pass them as parameters
$postvalues .= "&genders=".$genders;
$postvalues .= "&roles=".$roles;
// Finally building the page navigation
$pagenav = construct_page_nav($pagenumber, $perpage, $records, 'dating.php?' . $vbulletin->session->vars['sessionurl'] . 'do=searchresults'.$postvalues.'');

I also tried in postvalues:
Code:

$postvalues .= "&genders=".implode(',',$genders);
This changed the URL to &genders=1,2 but still can't get the values. Don't know if in this case I must use: TYPE_STR instead of TYPE_ARRAY_INT

Any idea is welcome :)

Thank you

Lynne 10-17-2014 05:48 PM

Since you are getting passed a single value (ie. initially it is genders=1 or genders=2, right?), then it is simply a string or integer at that point - it isn't an array that is getting passed via the URL.

TheAdminMarket 10-17-2014 06:13 PM

Quote:

Originally Posted by Lynne (Post 2519179)
Since you are getting passed a single value (ie. initially it is genders=1 or genders=2, right?), then it is simply a string or integer at that point - it isn't an array that is getting passed via the URL.

First of all thank you for your prompt attention. You're always here to help people. Really appreciated.

No, I'm passimg array of values from the initial form to genders[]. The first page works just fine. I'm using these array values to preselect the form that exists in the searchresults page.

The problem starts to appear when I'm navigating to any other page using the pagination (always on the same php file/page). The navigation works, but I'm loosing the values of the variables.

Maybe the solution can be childish. Is that $postvalues at the end of:
Code:

$pagenav = construct_page_nav($pagenumber, $perpage, $records, 'dating.php?' . $vbulletin->session->vars['sessionurl'] . 'do=searchresults'.$postvalues.'');
something needing for constructing the pagination, or not? If not then I believe that I can find a solution.

Thank you again

Lynne 10-17-2014 06:19 PM

You're passing an actual array? What does this URL look like initially - &genders=1,2&roles=1,2 ?

TheAdminMarket 10-17-2014 06:40 PM

Quote:

Originally Posted by Lynne (Post 2519187)
You're passing an actual array? What does this URL look like initially - &genders=1,2&roles=1,2 ?

Yes, the URL appears like that if I use the implode function like:
Code:

$postvalues .= "&genders=".implode(',',$genders);
$postvalues .= "&roles=".implode(',',$roles);

If I use:
Code:

$postvalues .= "&genders=".$genders;
$postvalues .= "&roles=".$roles;

then the URL looks like: &gender=Array&roles=Array

Lynne 10-17-2014 08:38 PM

I notice you aren't separating the post variables with "&" which would need to be done after do=searchresults (the session variable has one at the end). So, you need to fix that. But, I'd also suggest looking at the construct_page_nav function (in functions.php) because I'm not totally sure if it is set up to handle and array being passed.

TheAdminMarket 10-18-2014 06:24 AM

Finally I was able to solve the problem and I'm posting the solution here just in case someone else finds the same problem when passing arrays in URL. The trick is to use serialize/unserialize.

So in the passing to the URL you use:
PHP Code:

$url urlencode(serialize($array)) 

and to restore the variable you use
PHP Code:

$var unserialize(urldecode($_GET['array'])) 

Thank you very much Lynne.

Lynne 10-18-2014 04:55 PM

I'm glad you figured it out and thanks for posting the solution. :)


All times are GMT. The time now is 09:22 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01094 seconds
  • Memory Usage 1,736KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_code_printable
  • (2)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete