Jump to content

Display query result in a user friendly format, with each class in its own table


KitCarl
 Share

Recommended Posts

OK, Here is the code

 

$sql = "SELECT
TrialListing.listingID AS Trial, TrialClass.classID AS Class, place.place_name AS Place,
CONCAT_WS(
	' ',
	pedigree.pretitle,
pedigree.`Name`) AS Hound,
CONCAT_WS(
	' ',
	ped2.pretitle,
	ped2. NAME
)AS Sire,
CONCAT_WS(
	' ',
	ped3.pretitle,
	ped3. NAME
)AS Dam,
pedigree.Breeder,
pedigree.`Owner`,		
		CASE
		WHEN placement.place_id < 5 THEN
			TRUNCATE(TrialClass.number_of_entrants / placement.place_id,2)
		WHEN placement.place_id	 = 5 THEN
			''
		ELSE
			0
		END

AS Score
FROM
TrialListing
Left Join TrialClass ON TrialListing.listingID = TrialClass.listingID

JOIN placement ON placement.event_id = TrialClass.trialClassID
JOIN pedigree ON pedigree.PedigreeId = placement.hound_id
LEFT OUTER JOIN pedigree AS ped2 ON pedigree.SireId = ped2.PedigreeId
LEFT OUTER JOIN pedigree AS ped3 ON pedigree.DamId = ped3.PedigreeId
LEFT JOIN place ON place.place_id = placement.place_id

WHERE
TrialListing.listingID = 11
ORDER BY Class, FIELD(place.place_id, '1', '2', '3', '4', '0')


";      // Database Query  

$result = mysql_query("$sql");  // Database Query result

$num_rows = mysql_num_rows($result);





// Starts the table
echo "<table class=\"clubList\">\n
<tr>
<th>trialID</th>
<th>ClassID</th>
<th>Place</th>
<th>Hound</th>
<th>Sire</th>
<th>Dam</th>
<th>Score</th>

</tr>";

// Create the contents of the table.
for( $i = 0; $i < $row = mysql_fetch_array($result); $i++){




echo "<tr>\n"
        ."<td>".$row["Trial"]."</td>\n" 
        ."<td>".$row["Class"]."</td>\n" 
        ."<td>".$row["Place"]."</td>\n"  
        ."<td>".$row["Hound"]."</td>\n"  
        ."<td>".$row["Sire"]."</td>\n"                
        ."<td>".$row["Dam"]."</td>\n"
        ."<td>".$row["Score"]."</td>\n"  		
        ."</tr>";}



echo "</TABLE>";

 

Here is the output, I added the TrialID & ClassID for informational purposes, they do not need to be displayed in the live table.

 

trialID

ClassID

Place

Hound

Sire

Dam

Score

 

11

1

1st

Eaton Brook Tug Hill Tatonka

 

Eaton Brook Hickety Hawk

Eaton Brook Gunner's Beulah

[/td]

43.00

11

1

 

2nd

FC North Bend Igloo

FC DFJ Murphy White

IFC Brad-Ju's Bella Donna

21.50

11

 

1

3rd

FC North Bend Igloo

FC DFJ Murphy White

IFC Brad-Ju's Bella Donna

14.33

 

11

1

4th

Rail Road Spike VI

Elwell's Mike

Elwell's Hannah

 

10.75

11

1

NBQ

FC Fish Creek Spike

Fish Creek Bull II

Fish Creek Susie [H849395]

 

11

2

1st

Enman Hill Sweet Poppy

FTCH Straight Arrow

 

Lucky of Coos

32.00

11

2

2nd

Fishflakes Penny At Harehaven

 

FTCH Jill's Fair-Isle Spud

FTCH Millbridge Brownie

16.00

11

2

3rd

 

Line Elm Flakers

IFC Flakers Rex

IFC Line Elm Ginger

10.66

11

2

 

4th

FTCH Fareast Mookie

FTCH Mellowrun Sly

FTCH Cape Breton Maude

8.00

11

 

2

NBQ

FTCH Mellowrun Sly

Mellowrun Skylighter

FTCH Mellowrun Becka

 

11

3

1st

Bojangle V

Lee Otworth

Half Acre's Cocoa Candy

 

23.00

11

3

2nd

Gay Doll

Gay Roll II

 

Gay Idol

11.50

11

3

3rd

Bruce's Blue Lady

 

FC Kilsock's Blue Creek Bart

Bishopville's Zippy

7.66

11

3

4th

 

FC Pearson Creek Barbin

FC Pearson Creek Barbarian

FC B-Line Stubby

5.75

11

3

 

NBQ

Sims Creek Cricket

Ronnie Joe

Sims Creek Tiny

 

11

4

1st

FTCH Fareast Mookie

FTCH Mellowrun Sly

FTCH Cape Breton Maude

26.00

 

11

4

2nd

FTCH Mellowrun Sly

Mellowrun Skylighter

FTCH Mellowrun Becka

 

13.00

11

4

3rd

Fishflakes Penny At Harehaven

FTCH Jill's Fair-Isle Spud

FTCH Millbridge Brownie

 

8.66

11

4

4th

Enman Hill Sweet Poppy

FTCH Straight Arrow

 

Lucky of Coos

6.50

11

4

NBQ

Line Elm Flakers

 

IFC Flakers Rex

IFC Line Elm Ginger

 

Below is what I would like to generate. How do I word or nest the proper PHP code/loops to accomplish this?

 

ClassID

 

 

Place

Hound

Sire

Dam

Score

 

 

1st

Eaton Brook Tug Hill Tatonka

Eaton Brook Hickety Hawk

Eaton Brook Gunner's Beulah

43.00

 

 

2nd

FC North Bend Igloo

FC DFJ Murphy White

IFC Brad-Ju's Bella Donna

21.50

 

3rd

FC North Bend Igloo

FC DFJ Murphy White

IFC Brad-Ju's Bella Donna

14.33

 

 

4th

Rail Road Spike VI

Elwell's Mike

Elwell's Hannah

 

10.75

 

NBQ

FC Fish Creek Spike

Fish Creek Bull II

Fish Creek Susie [H849395]

 


 

ClassID

 

 

Place

Hound

Sire

Dam

Score

 

1st

Enman Hill Sweet Poppy

FTCH Straight Arrow

 

Lucky of Coos

32.00

 

2nd

Fishflakes Penny At Harehaven

 

FTCH Jill's Fair-Isle Spud

FTCH Millbridge Brownie

16.00

 

3rd

 

Line Elm Flakers

IFC Flakers Rex

IFC Line Elm Ginger

10.66

 

 

4th

FTCH Fareast Mookie

FTCH Mellowrun Sly

FTCH Cape Breton Maude

8.00

 

NBQ

FTCH Mellowrun Sly

Mellowrun Skylighter

FTCH Mellowrun Becka

 


 

ClassID

 

Place

Hound

Sire

Dam

Score

 

 

1st

Bojangle V

Lee Otworth

Half Acre's Cocoa Candy

 

23.00

 

2nd

Gay Doll

Gay Roll II

 

Gay Idol

11.50

 

3rd

Bruce's Blue Lady

 

FC Kilsock's Blue Creek Bart

Bishopville's Zippy

7.66

 

4th

 

FC Pearson Creek Barbin

FC Pearson Creek Barbarian

FC B-Line Stubby

5.75

 

 

NBQ

Sims Creek Cricket

Ronnie Joe

Sims Creek Tiny

 


 

ClassID

 

 

Place

Hound

Sire

Dam

Score

 

 

1st

FTCH Fareast Mookie

FTCH Mellowrun Sly

FTCH Cape Breton Maude

26.00

 

 

2nd

FTCH Mellowrun Sly

Mellowrun Skylighter

FTCH Mellowrun Becka

 

13.00

 

3rd

Fishflakes Penny At Harehaven

FTCH Jill's Fair-Isle Spud

FTCH Millbridge Brownie

 

8.66

 

4th

Enman Hill Sweet Poppy

FTCH Straight Arrow

 

Lucky of Coos

6.50

 

NBQ

Line Elm Flakers

 

IFC Flakers Rex

IFC Line Elm Ginger

[td]

 

 

 

Link to comment
Share on other sites

pseudo-code:

 

$OLD-Classid = "";

// Create the contents of the table.
for( $i = 0; $i < $row = mysql_fetch_array($result); $i++){

  if ($row['Class'] != $OLD-Classid) {
     // Here Print $row['Class'] in the way you want
     $OLD-Classid = $row['Class'];
  }
  // Print the rest of fields

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.