Hey Was making some systems etc and I'm always too lazy to make sort (when you click e.g. Name and it sort by name) :/ So I decided to make some functions so it will take seconds to configure this sorting
Now, here are some functions (if you use gesior's AAC, place in config-and-functions.php):
How to use?? Simple.
First you make an array, like this for example:
The key means what will be displayed, and the value is the database field name. Which means if I have "order=guild" it will order by field "name" in database.
Then in your SQL query you do like this:
First parameter is the array, second is the GET-name ('order' means $_GET['order']) and last ('end') is default sort...
Now to the final part, to display the links:
First parameter is array, second id GET-name, last is what will be in GET (e.g. &order=guild)...
The point of adding getOrder and not writing yourself is because it will make auto asc, desc.
So it will become like &order=guild_asc, and next time you click it will become &order=guild_desc
IF YOU LIKE IT, DON'T FORGET REP++ :thumbup:
Regards,
Colandus
Now, here are some functions (if you use gesior's AAC, place in config-and-functions.php):
PHP:
function makeOrder($arr, $order, $default) {
// Function by Colandus!
$type = 'asc';
if(isset($_GET['order'])) {
$v = explode('_', strrev($_GET['order']), 2);
if(count($v) == 2)
if($orderBy = $arr[strrev($v[1])])
$default = $orderBy;
$type = (strrev($v[0]) == 'asc' ? 'desc' : 'asc');
}
return 'ORDER BY ' . $default . ' ' . $type;
}
function getOrder($arr, $order, $this) {
// Function by Colandus!
$type = 'asc';
if($orderBy = $arr[$this])
if(isset($_GET[$order])) {
$v = explode('_', strrev($_GET[$order]), 2);
if(strrev($v[1]) == $this)
$type = (strrev($v[0]) == 'asc' ? 'desc' : 'asc');
}
return $this . '_' . $type;
}
How to use?? Simple.
First you make an array, like this for example:
PHP:
$order = array(
"guild" => "name",
"versus" => "target_name",
"status" => "end",
"started_at" => "start"
);
The key means what will be displayed, and the value is the database field name. Which means if I have "order=guild" it will order by field "name" in database.
Then in your SQL query you do like this:
PHP:
$warList = $SQL->query('SELECT * FROM guild_history ' . makeOrder($order, 'order', 'end'));
First parameter is the array, second is the GET-name ('order' means $_GET['order']) and last ('end') is default sort...
Now to the final part, to display the links:
PHP:
$main_content .= '
<table border=0 cellspacing=1 cellpadding=4 width=100%>
<tr bgcolor="'.$config['site']['vdarkborder'].'">
<td align="center"><a href="index.php?subtopic=war&order=' . getOrder($order, 'order', 'guild') . '" class=white>Guild</a></td>
<td align="center"><a href="index.php?subtopic=war&order=' . getOrder($order, 'order', 'versus') . '" class=white>Versus</a></td>
<td align="center"><a href="index.php?subtopic=war&order=' . getOrder($order, 'order', 'status') . '" class=white>Status</a></td>
<td align="center"><a href="index.php?subtopic=war&order=' . getOrder($order, 'order', 'started_at') . '" class=white>Started at</a></td>
<td align="center"><b><font color="white">Kills</font></b></td>
</tr>
' . $war_rows . '
</table>
';
First parameter is array, second id GET-name, last is what will be in GET (e.g. &order=guild)...
The point of adding getOrder and not writing yourself is because it will make auto asc, desc.
So it will become like &order=guild_asc, and next time you click it will become &order=guild_desc
IF YOU LIKE IT, DON'T FORGET REP++ :thumbup:
Regards,
Colandus