php - Sort a list without refreshing the page -



php - Sort a list without refreshing the page -

i have next code:

<table border="0" width="100%"><tbody> <tr> <th style="text-align: center;"><?php echo $text['players']; ?></th> </tr> <tr> <td> <select name="order" size="1" onchange="sortplayers(this)"> <option value="name"><?php echo $text['name']; ?></option> <option value="age"><?php echo $text['age']; ?></option> <option value="ss"><?php echo $text['ss']; ?></option> <option value="experience"><?php echo $text['experience']; ?></option> <option value="leadership"><?php echo $text['leadership']; ?></option> <option value="weight"><?php echo $text['weight']; ?></option> <option value="height"><?php echo $text['height']; ?></option> <option value="stamina"><?php echo $text['stamina']; ?></option> <option value="strength"><?php echo $text['strength']; ?></option> <option value="breakthroughs"><?php echo $text['breakthroughs']; ?></option> <option value="tackling"><?php echo $text['tackling']; ?></option> <option value="handling"><?php echo $text['handling']; ?></option> <option value="speed"><?php echo $text['speed']; ?></option> <option value="kicking"><?php echo $text['kicking']; ?></option> </select> </td> </tr> <?php foreach ($result $player) { ?> <tr> <td style="text-align: left;"><?php echo $player['male'] . ' ' . $player['name']; ?></td> </tr> <?php } ?> </tbody></table>

it generates list every users players in online game. want when user selects dropdown menu, players sorted has been selected (strength, speed, etc.). have function players: get_players ($ tid, $ sort). $tid = user id $sort = sorting criteria (speed, kicking, etc.).

what javascript code selected in input , alter variable $result depending on selection in input, without refreshing page.

if understand want correctly, want viewer able select alternative (name, age, ss, experience, etc...) , have different sorted results display depending upon attribute selected , want without refreshing page.

from design point of view, have 2 ways go. can include in initial page (in javascript info structure) possible info selections. then, it's matter of javascript code fetch right piece of info data structure, sort , insert dom display.

or, if don't pre-include data, have create ajax phone call fetch desired data, sort , insert dom. php show in code right looks it's including player's name.

which way go depends upon scale of data. if it's manageable (from speed of generating page , browser memory consumption point of view) include info in original page, easier code. but, have @ worst case of max number of players, max number of attributes support. if that's not manageable, need back upwards ajax phone call can homecoming json info given attribute has been selected.

php javascript

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -