tarbender89 Posted August 18, 2010 Share Posted August 18, 2010 MySQL Version: 5.1 $database="tarb89_ausus"; mysql_connect ("localhost", "tarb89_admin", "leccums"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT * FROM characters ORDER BY `player`") or die("SELECT Error: ".mysql_error()); $num = mysql_num_rows($result); if ($num > 0 ) { $i=0; while ($i < $num) { $character_name = mysql_result($result,$i,"character_name"); $breed = mysql_result($result,$i,"breed"); $gender = mysql_result($result,$i,"gender"); $base_color = mysql_result($result,$i,"base_color"); $markings = mysql_result($result,$i,"markings"); $genetics = mysql_result($result,$i,"genetics"); $sire = mysql_result($result,$i,"sire"); $dam = mysql_result($result,$i,"dam"); $other = mysql_result($result,$i,"other"); $player = mysql_result($result,$i,"player"); $id = mysql_result($result,$i,"id"); echo "<b>$player</b><br>Horse ID Number: $id - $character_name - $breed - $gender - $base_color - $markings - $genetics - $sire - $dam - $other<br><br>"; ++$i; } } There are no errors in my statement as it displays what it's wrote to display correctly. What my question is, how do I display all of the queries in one table based on the entries of one column? The best way for me to explain this is to demonstrate HOW I want the results to display on my website. I would like it to display like the following: PLAYER ONE - Character one, character information - Character two, character information PLAYER TWO - Character one, character information - Character two, character information So on and so forth. I only want the Players to display once, but I want all of the characters and character information with the same player to display underneath the player name. I've tried a million different ways, and I'm just too new to PHP and MySQL I guess to figure this out. Any help would be extremely helpful. Hopefully I got all of the information down from the rules.. Don't be too hard on the noob! Quote Link to comment https://forums.phpfreaks.com/topic/211093-displaying-mysql-data-based-on-one-column/ Share on other sites More sharing options...
DavidAM Posted August 18, 2010 Share Posted August 18, 2010 Track the last player you processed and only print the name if it is different from the current one. $database="tarb89_ausus"; mysql_connect ("localhost", "tarb89_admin", "leccums"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT * FROM characters ORDER BY `player`") or die("SELECT Error: ".mysql_error()); $num = mysql_num_rows($result); if ($num > 0 ) { $i=0; $lastPlayer=''; // TRACK THE LAST PLAYER TO PREVENT HEADINGS while ($i < $num) { $character_name = mysql_result($result,$i,"character_name"); $breed = mysql_result($result,$i,"breed"); $gender = mysql_result($result,$i,"gender"); $base_color = mysql_result($result,$i,"base_color"); $markings = mysql_result($result,$i,"markings"); $genetics = mysql_result($result,$i,"genetics"); $sire = mysql_result($result,$i,"sire"); $dam = mysql_result($result,$i,"dam"); $other = mysql_result($result,$i,"other"); $player = mysql_result($result,$i,"player"); $id = mysql_result($result,$i,"id"); // PRINT PLAYER NAME IF DIFFERENT FROM THE LAST ONE if ($lastPlayer != $player) { // IF YOU WANT A BLANK LINE BETWEEN GROUPS if ($lastPlayer != '') echo "<br>"; echo "<b>$player</b><br>"; $lastPlayer = $player; } echo "Horse ID Number: $id - $character_name - $breed - $gender - $base_color - $markings - $genetics - $sire - $dam - $other<br><br>"; ++$i; } } Quote Link to comment https://forums.phpfreaks.com/topic/211093-displaying-mysql-data-based-on-one-column/#findComment-1100880 Share on other sites More sharing options...
tarbender89 Posted August 18, 2010 Author Share Posted August 18, 2010 Oh goodness, you are my hero right now. I've been trying to get my little noob mind to wrap around this concept for weeks now. Thank you.. tremendously. This problem is finally solved! Quote Link to comment https://forums.phpfreaks.com/topic/211093-displaying-mysql-data-based-on-one-column/#findComment-1100882 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.