Hello all,
my first post here and have a question to save some of my hair that i have been pulling out. I am a beginner at php/mysql that i have been dabbing into lately and have a question about an output i am trying to do.
I have 3 tables and it is about golf.
1) table -> course
field (1) -> course_id [ int ]
field (2) -> cname [ course name ]
2) table -> hole
field (1) -> course_id [ int ]
field (2) -> hole_no [ int ]
field (3) -> tee_color_id [ int ]
3) table -> tee_color
field (1) -> tee_color_id [ int ]
field (2) -> color [ varchar ]
what i am trying to do is output table (1) course name with all the associates tee color, table (3) with all the hole numbers assocaited with the course and tee color. here is the code i have so far and it is only outputing 1 row only. I know i need to search all the rows, but i dont know where to go.
this is what i would like to show:
Course name [ single course name ] - Tee color [ specific tee color ] - Hole numbers [ all the hole numbers 1 - 9 or 1 - 18 ]
<?php
// GOLF HOLE LIST BELOW
$columns = 9;
$holequery = "SELECT * FROM course AS a, hole AS b, tee_color AS c WHERE a.course_id = b.course_id AND b.tee_color_id = c.tee_color_id AND b.hole_no ORDER BY a.course_id";
$result = mysql_query($holequery);
$num_rows = mysql_num_rows($result);
//we are going to set a new variables called $rows
$rows = ceil($num_rows / $columns);
echo "<TABLE BORDER=\"1\">\n";
//to do this display, we will need to run another loop
//this loop will populate an array with all our values
while($row = mysql_fetch_array($result)) {
$coursename = $row['cname'];
$tcolor = $row['color'];
$data[] = $row['hole_no'];
//echo "<TABLE BORDER=\"1\">\n";
echo "<tr>\n";
echo " <td rowspan=\"$rows\">\n";
echo "$coursename\n";
echo " </td>\n";
echo " <td>\n";
echo "$tcolor\n";
echo " </td>\n";
//here we changed the condition to $i < $rows
for($i = 0; $i < $num_rows; $i++) {
//$row = mysql_fetch_array($result);
if($i % $columns == 0) {
//if there is no remainder, we want to start a new row
echo "<TR>\n";
}
echo "<TD>" . $row['hole_no'] . "</TD>\n";
if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
//if there is a remainder of 1, end the row
//or if there is nothing left in our result set, end the row
echo "</TR>\n";
}
}
}
echo "</TABLE>\n";
?>
oh yeah my output:
Monarch Bay White
1 1 1 1 1 1
Monarch Bay White
2 2 2 2 2 2
Monarch Bay White
3 3 3 3 3 3
Monarch Bay White
4 4 4 4 4 4
Monarch Bay White
5 5 5 5 5 5
Tilden Park Middle
1 1 1 1 1 1
should be:
Monarch Bay | white | 1 2 3 4 5
Tilden Park | Middle | 1
etc
Thanks for your time viewing this issue for me