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
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