brown2005 Posted June 2, 2006 Share Posted June 2, 2006 Right, what I want to do is create three lists..... in ranking order... BASED ON THE NUMBER OF THEM, I.E. IF THERE IS 5 RICHARDS AND 3 EMILYS....1. FIRST NAMES - BOTH MALES AND FEMALES1 - RICHARD - 52 - EMILY - 32. FIRST NAMES - MALES ONLY1 - RICHARD - 53. FIRST NAMES - FEMALES ONLY1 - EMILY - 3the table is membersand has the following fieldsmembers_firstnamemembers_sex Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/ Share on other sites More sharing options...
brown2005 Posted June 2, 2006 Author Share Posted June 2, 2006 what i forgot to put is that i want them in the same table though. Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41312 Share on other sites More sharing options...
Barand Posted June 2, 2006 Share Posted June 2, 2006 Something like this maybe[code]function rankNames ($sex='') { $sql = "SELECT firstname, COUNT(*) as total FROM members WHERE sex LIKE '$sex%' GROUP BY firstname ORDER BY total DESC"; $res = mysql_query($sql) or die(mysql_error()); switch ($sex) { case 'M': echo '<br>MALES ONLY<br>'; break; case 'F': echo '<br>FEMALES ONLY<br>'; break; default: echo '<br>MALE and FEMALE<br>'; break; } $rank=1; while (list($name, $tot) = mysql_fetch_row($res)) { echo "$rank $name $tot<br>"; ++$rank; }}rankNames();rankNames('M');rankNames('F');[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41313 Share on other sites More sharing options...
brown2005 Posted June 2, 2006 Author Share Posted June 2, 2006 Yeah thats cool i can use that....now wat if i wanted to put it into a table...RANK - ALL - MALES - FEMALElike that? any ideas please? Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41315 Share on other sites More sharing options...
Barand Posted June 2, 2006 Share Posted June 2, 2006 I can't think of many things more annoying than people saying"I know I said I wanted that but what I really want is this." Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41316 Share on other sites More sharing options...
brown2005 Posted June 2, 2006 Author Share Posted June 2, 2006 well if you see i put "what i forgot to put is that i want them in the same table though" before wat u wrote Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41322 Share on other sites More sharing options...
Barand Posted June 2, 2006 Share Posted June 2, 2006 So you think I set up a test database, wrote the code and tested it in 3 minutes? Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41327 Share on other sites More sharing options...
brown2005 Posted June 2, 2006 Author Share Posted June 2, 2006 no i dont..... ill make sure i put it all in the first bit next time.. sorry mate Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41329 Share on other sites More sharing options...
Barand Posted June 2, 2006 Share Posted June 2, 2006 Try[code]$ranks = array();$sql = "SELECT sex, firstname, COUNT(*) as total FROM members GROUP BY sex,firstname ORDER BY total DESC";$res = mysql_query($sql) or die(mysql_error());$rank = 0;while (list($sex, $name, $tot) = mysql_fetch_row($res)) { $ranks['BOTH'][] = array($name,$tot); $ranks[$sex][] = array($name,$tot); $rank++;}echo "<table border='1'>"; echo "<tr> <td>RANK</td> <td>ALL</td> <td>MALE</td> <td>FEMALE</td> </tr>";for ($r=1; $r<=$rank; $r++) { echo "<tr> <td>$r</td> <td>{$ranks['BOTH'][$r-1][0]} - {$ranks['BOTH'][$r-1][1]}</td> <td>{$ranks['M'][$r-1][0]} - {$ranks['M'][$r-1][1]}</td> <td>{$ranks['F'][$r-1][0]} - {$ranks['F'][$r-1][1]}</td> </tr>";}echo "</table>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41333 Share on other sites More sharing options...
brown2005 Posted June 3, 2006 Author Share Posted June 3, 2006 Thanks Barand. Exactly what I wanted.. Im sorry for the messing around in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41400 Share on other sites More sharing options...
Barand Posted June 3, 2006 Share Posted June 3, 2006 Just to make sure the data lists under the right heading, change first line to[code]$ranks = array( 'BOTH' => array(), 'M' => array(), 'F' => array());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41406 Share on other sites More sharing options...
brown2005 Posted June 3, 2006 Author Share Posted June 3, 2006 Hi,I don't know if its possib;e but with the colum under All, is there anyway to make the males one color and the females another color.And is it possible to change the 1000 to 1,000 Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41408 Share on other sites More sharing options...
Barand Posted June 3, 2006 Share Posted June 3, 2006 Define styles for M/F cells. Save sex in the array as well as name and count and use to define the TD.class.For the count, store number_format($tot,0);[code]<STYLE type="text/css"> TD.M {color: #8CAAE1} TD.F {color: #FFC0C0}</STYLE><?php include 'db.php';$ranks = array( 'BOTH' => array(), 'M' => array(), 'F' => array());$sql = "SELECT sex, firstname, COUNT(*) as total FROM members GROUP BY sex,firstname ORDER BY total DESC";$res = mysql_query($sql) or die(mysql_error());$rank = 0;while (list($sex, $name, $tot) = mysql_fetch_row($res)) { $ranks['BOTH'][] = array($name, number_format($tot, 0), $sex); $ranks[$sex][] = array($name, number_format($tot, 0), $sex); $rank++;}echo "<table border='1'>"; echo "<tr> <td>RANK</td> <td>ALL</td> <td>MALE</td> <td>FEMALE</td> </tr>";for ($r=1; $r<=$rank; $r++) { echo "<tr> <td>$r</td> <td class='{$ranks['BOTH'][$r-1][2]}'>{$ranks['BOTH'][$r-1][0]} - {$ranks['BOTH'][$r-1][1]}</td> <td class='{$ranks['M'][$r-1][2]}'>{$ranks['M'][$r-1][0]} - {$ranks['M'][$r-1][1]}</td> <td class='{$ranks['F'][$r-1][2]}'>{$ranks['F'][$r-1][0]} - {$ranks['F'][$r-1][1]}</td> </tr>";}echo "</table>";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41410 Share on other sites More sharing options...
brown2005 Posted June 3, 2006 Author Share Posted June 3, 2006 Thanks mate... Thanks for all your help...... Quote Link to comment https://forums.phpfreaks.com/topic/11054-solved-ranking-table/#findComment-41413 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.