• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP] Sort function

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,764
Solutions
1
Reaction score
227
Location
Chile, Santiago
Hey there, Im using modern AAC but the sort function isnt working :S

Actually it looks like this:

PHP:
echo "<b>Sort by </b> &nbsp; <select name='sort'>";
echo "<option  value=''>None</option>";
echo "<option ".set_select('sort', 'level')." value='level'>Level</option>";
echo "<option ".set_select('sort', 'Vocation')." value='Vocation'>Profession</option>";
echo "<option ".set_select('sort', 'name')." value='name'>Name</option>";
echo "</select>";
echo "&nbsp; <input type='submit' value='Order'>";
echo "</form>";
 
echo "</form>";
if(count($players) > 0) {
	echo "<table width='100%'>";
	echo

But when you submite the sort selection, it doesn't sort the players... Any one could give me a working example on how to sort them?
 
Thanks, and why this doesn't work:

PHP:
$ide = new IDE;
	try { $ide->loadInjections("players_online"); } catch(Exception $e) { error($e->getMessage()); }
echo form_open("character/online", array('method'=>'POST'));
if(count($config['worlds']) > 1) {
	echo "<b>World </b> &nbsp; <select name='world'>";
	echo "<option value=''>All</option>";
	foreach($config['worlds'] as $key=>$value) {
		echo "<option ".set_select('world', $key)." value='$key'>$value</option>";
	}
	echo "</select>&nbsp; &nbsp;";
	
}
echo "<b>Ordenar por: </b> &nbsp; <select name='sort'>";
echo "<option  value=''>None</option>";
echo "<option ".set_select('sort', 'level')." value='level'>Level</option>";
echo "<option ".set_select('sort', 'vocation')." value='vocation'>Profession</option>";
echo "<option ".set_select('sort', 'name')." value='name'>Name</option>";
echo "</select>";
echo "&nbsp; <input type='submit' value='sort'>";
echo "</form>";

Since it checks the new ide and return the players sorted?
 
Maybe more simple... I want to do something like this:

PHP:
echo '<div class="message"><div class="title">Who is Online</div></div>';
echo "<b>Sort by </b> &nbsp; <select name='sort'>";
echo "<option  value=''>None</option>";
echo "<option ".set_select('sort', 'level')." value='level'>Level</option>";
echo "<option ".set_select('sort', 'Vocation')." value='Vocation'>Profession</option>";
echo "<option ".set_select('sort', 'name')." value='name'>Name</option>";
echo "</select>";
echo "&nbsp; <input type='submit' value='Order'>";
echo "</form><hr>";

echo "</form>";

$players = "SELECT * FROM  `players` WHERE  `online` = 1 SOME HOW PUT SET_SELECT";
$players = $SQL->query($players)->fetchAll();
foreach($players as $player) {
		...
	}

Check the SOME HOW PUT SET_SELECT part.
 
I suppose this should do the trick...
PHP:
$allowed_sorts = array(
    'level'    => 'ORDER BY experience DESC',
    'vocation' => 'ORDER BY vocation_id ASC',
    'name'     => 'ORDER BY name ASC',
);

$sort_post = strtolower($_POST['sort']);
$sort = isset($sort_post, $allowed_sorts[$sort_post]) ? $allowed_sorts[$sort_post] : $allowed_sorts['name'];

$players = "SELECT * FROM  `players` WHERE  `online` = 1 {$sort}";
 
Back
Top