blakogre Posted June 27, 2006 Share Posted June 27, 2006 Thanks to all who've helped before: [a href=\"http://www.blakogre.com/epix/altdkp.php\" target=\"_blank\"]http://www.blakogre.com/epix/altdkp.php[/a] was the result. THANKS!I've snipped the following code from a page which I've partially modified, but it's still not quite what I want: [a href=\"http://www.blakogre.com/guildviewer.php\" target=\"_blank\"]http://www.blakogre.com/guildviewer.php[/a][!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<tr> <td><b>Name</b></td> <td><b>Level</b></td> <td><b>Rank</b></td> <td><b>Note</b></td></tr>OUTPUT;ksort($classes); <-sorting by classes? This makes my major grouping?foreach ($classes as $ckey => $class) { <-ckey -- that's defined here as teh $class variable ksort($class); <- but... this sorts by class... so I'm not sure why there are 2. maybe created array? lost. echo <<<OUTPUT<tr> <td colspan="4"><b>{$ckey}</b></td> <-- and this line is where ckey/class is inserted at each group</tr>OUTPUT; foreach ($class as $member) { $member['Name'] = htmlentities($member['Name']); $member['Rank'] = htmlentities($member['Rank']); $member['Note'] = htmlentities($member['Note']); echo <<<OUTPUT<tr> <td>{$member['Name']}</td> <td>{$member['Level']}</td> <td>{$member['Rank']}</td> <td>{$member['Note']}</td></tr>OUTPUT; }}echo <<<OUTPUT</table>OUTPUT;?>[/quote]Within each "Class" I want to sort by descending level as well: can I add another ksort in there? I've tried that, but I know my synatx is off, as I don't quite 100% understand what each line does. The pure HTML I get, it's the rest. I added my notes/what I think is going on. But again, I"m not a programmer, I come from an admin background.Thx -- any help appreciated. My goals are simply for it to work, however, understanding it is great too. I love to learn by tweaking and playing and trying to get results I want.So, it creates major class groupings, and then within that, ideally:Sort by descending lvland within lvlSort by ascending nameBob 60Charles 60Alan 55Trudie 30Jack 28Kevin 28(The data is stored in another PHP page -- page one "parser.php" parses a text file, which creates page 2 "data.php", which feeds into this page, "viewer.php") Quote Link to comment https://forums.phpfreaks.com/topic/13049-php-ksort-help/ Share on other sites More sharing options...
thepip3r Posted June 27, 2006 Share Posted June 27, 2006 if the inforamtion is in a DB, use SQL DESC to have your array automatically sorted that way.if you have the data in an array, do a numeric sort on the second element of the second dimension and reverse results. you may have to convert the value to an integer... Quote Link to comment https://forums.phpfreaks.com/topic/13049-php-ksort-help/#findComment-50220 Share on other sites More sharing options...
blakogre Posted June 27, 2006 Author Share Posted June 27, 2006 Well, I added:OUTPUT;[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]ksort($classes);foreach ($classes as $ckey => $class) { ksort($class); echo <<<OUTPUT<tr> <td colspan="4"><b>{$ckey}</b></td></tr>OUTPUT; [b]sort($level);[/b] foreach ($level as $member) { [b]sort($level);[/b] $member['Name'] = htmlentities($member['Name']); $member['Rank'] = htmlentities($member['Rank']); $member['Note'] = htmlentities($member['Note']); echo <<<OUTPUT<tr> <td>{$member['Name']}</td> <td>{$member['Level']}</td> <td>{$member['Rank']}</td> <td>{$member['Note']}</td>[/quote]Of course, not working. I don't have 100% understanding or even close -- the "<--" comments in the first post are mine, trying to wrap my brain around it all. Quote Link to comment https://forums.phpfreaks.com/topic/13049-php-ksort-help/#findComment-50238 Share on other sites More sharing options...
blakogre Posted June 27, 2006 Author Share Posted June 27, 2006 The initial array:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$classes = [b]array();[/b]foreach ($guilddata['Members'] as $name => $info) { if (empty($classes[$info['Class']])) { $classes[$info['Class']] = array(); } $classes[$info['Class']][$name] = $info;}[/quote]So -- I think in the () I need values I can reference for the sort? Tried putting things in -- got errors.... Quote Link to comment https://forums.phpfreaks.com/topic/13049-php-ksort-help/#findComment-50244 Share on other sites More sharing options...
blakogre Posted June 27, 2006 Author Share Posted June 27, 2006 I also tried adding a line like krsort($members['Level'])and got:Warning: krsort() expects parameter 1 to be array, string given in C:\Inetpub\boc\guildviewer.php on line 137added right before the last echo<<<output above (ditched the sort/$level stuff) Quote Link to comment https://forums.phpfreaks.com/topic/13049-php-ksort-help/#findComment-50255 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.