PDA

View Full Version : pagination and drop down session


Mickie D
06-11-2015, 05:12 PM
I have successfully setup pagination for my new modification, which gets the information from the database then limits the results to 10 items per page.

The only trouble is that I would now like to sort the items by different values, but I am not sure how sessions work in the respect do I need to add a column to the MySQL database or just setup a session variable?

This is my code:


$orderby = $vbulletin->input->clean_gpc('p', 'orderby', TYPE_NOTRIM);

if(isset($orderby) ){

switch ($orderby){
case "1": $order = "file_fullsize"; /*$sel_full = "selected='selected'";*/ break;
case "2": $order = "file_timestamp"; /*$sel_time = "selected='selected'";*/ break;
case "3": $order = "file_name"; /*$sel_name = "selected='selected'";*/ break;
default: $order = "file_fullsize";
}
}

$dir = '/temp/'.$vbulletin->userinfo['username'] . "/";
$dirsql = $vbulletin->db->query_read("SELECT * FROM " . TABLE_PREFIX . "web WHERE file_userid = '$r1' ORDER BY $order DESC LIMIT $limitlower, $perpage");


Code for the dropdown

<form id="form1" name="form1" method="post" action="web.php">
<select name="orderby">
<option value="1" name="file_fullsize">File Size</option>
<option value="2" name="file_timestamp">File Added</option>
<option value="3" name="file_name">File Name</option>
</select>

<input type="submit" />
</form>


This works great for page one of the pagination but because the pagination changes pages it just defaults the switch on any other page

file_fullsize

I guess that i need to store the drop down orderby variable across the pagination?

Thank you for any help
Mick

cellarius
06-12-2015, 04:28 AM
You need to add your sort value to the pagination url parameters, then retrieve it (using get, not post in the input cleaner).

Don't forget to set your dropdown to the chosen value.

Mickie D
06-12-2015, 04:46 AM
You need to add your sort value to the pagination url parameters, then retrieve it (using get, not post in the input cleaner).

Don't forget to set your dropdown to the chosen value.

Thank you very much for you help.

I used the guide on here to setup the pagination,


This code is used in the pagination, to be honest, I did not take much notice of it just that it worked... But is this where I need to append the GET of the orderby value?



$pagenav = construct_page_nav(
$vbulletin->GPC['pagenumber'],
$perpage,
$file_pages['files_count'],
'web.php?' . $vbulletin->session->vars['sessionurl'], // the pagenav-link
'', // to pass a second portion or the pagenav-link, gets directly appended to above
'', // to pass an anchor
'', // SEO-Link for thread, forum, member... pages - make the pagenav-links seo'ed if you use the paginator on one of those
'', // Array to pass linkinfo for SEO-Link-Method
'' // Array to pass additional Info for SEO-Link-Method
);


Thank you again, much appreciated :)

Mick

--------------- Added 1434095288 at 1434095288 ---------------

Cellerus you are a Legend, it was so easy when you think about it!!!

For anyone looking for the same issue I did as said above changed everything to GET (not POST). then just added in the orderby into the pagination construct :)



$pagenav = construct_page_nav(
$vbulletin->GPC['pagenumber'],
$perpage,
$file_pages['files_count'],
'webspace.php?' . $vbulletin->session->vars['sessionurl'],
'&orderby='.$orderby // THIS IS WHERE I ADDED THE FORM CALL

);

cellarius
06-12-2015, 05:58 AM
Glad you got it sorted (pun fully intended) ;)