Jump to content

Recommended Posts

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!

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; } } 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.