I am looking to echo values from two tables which are related on a HTML page. To do this I have queried the tables and set a while loop within a while loop to echo the output.
The database tables each have a column of a unique_id which is a foreign key in the next table. The first table is queried using the session email of the user to get that unique_id. The next table is then queried using that value.
The first set of data echo's fine but the next is blank.
Code:
<!DOCTYPE HTML>
<html>
<head>
<title>Your Scorecards</title>
<link rel="icon" type="image/x-icon" href="../assets/favicon-32x32.png">
<link rel="stylesheet" href="stylesheet.css">
</head>
<body>
<?php include_once 'header.php'; ?>
<?php
$connect =mysqli_connect('localhost','root','','micaddy');
$id_query = mysqli_query($connect, "SELECT unique_id FROM users WHERE email = '{$_SESSION['login_user']}'");
$id_array = mysqli_fetch_assoc($id_query);
$uid = $id_array['unique_id'];
$result = mysqli_query($connect, "SELECT * FROM rounds WHERE user_id = '$uid'");
$rnd_id_query = mysqli_query($connect, "SELECT unique_id FROM rounds WHERE user_id = '$uid'");
$rnd_id_array = mysqli_fetch_assoc($rnd_id_query);
$round_id = $rnd_id_array['unique_id'];
$hole = mysqli_query($connect, "SELECT * FROM holes WHERE course_id = '$round_id'");
?>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading clearfix"><h3 class="panel-title"><strong>Your Rounds</strong></h3></div>
<?php while($row=mysqli_fetch_assoc($result)):?>
<div class="panel-body">
<div class="container-fluid">
<div class="row">
<div class="col-lg-5">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title"><strong><?php echo $row['course_name'];?>   <?php echo $row['round_date']?> </strong></h3></div>
<div class="panel-body">
<table style="width:100%">
<tr>
<th>Hole Number</th>
 
<th>Yards</th>
 
<th>Par</th>
 
<th>Shots</th>
<?php while($hole_row=mysqli_fetch_assoc($hole)): ?>
<?php if($hole_row['course_id'] === $row['unique_id']){ ?>
<tr>
<td><?php echo $hole_row['hole_number']; ?></td>
<td><?php echo $hole_row['yards']; ?></td>
<td><?php echo $hole_row['par']; ?></td>
<td><?php echo $hole_row['shots']; ?></td>
</tr>
<?php } ?>
<?php endwhile; ?>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endwhile;?>
</div>
</div>
</div>
</div>
<?php include_once 'footer.php'; ?>
</body>
</html>
