How can I hide columns shown as empty fields?
Hi, I am trying to display baby names for boys and girls in a table format. I have had to display them in terms of gender, so below is what i have at the moment which works however, when i select a letter, it displays both boysnames and girlsnames and then also adds loads of extra empty columns
see code below:
echo "<div class='bigMargin'>";
if (isset($_GET["initial"])) {
$initial=$_GET["initial"];
$dbQuery=$conn->prepare("select * from babynames where babyNames like :initial");
$initial=$initial.'%';
$dbParams=array('initial'=>$initial);
$dbQuery->execute($dbParams);
$arr = array();
$count = 0;
while($dbRow = $dbQuery->fetch(PDO::FETCH_ASSOC)) {
if($dbRow['gender'] === 'B') { $arr['BoysName'][] = $dbRow['babyNames']; }
elseif($dbRow['gender'] === 'G') { $arr['GirlsName'][] = $dbRow['babyNames']; }
$count++;
}
echo '<center>
<table border="1" width="400">
<tr>
<th>Boy Names</th>
<th>Girls Names</th>
</tr>';
$i = 0;
while($i < $count) {
echo '<tr>';
if(isset($arr['BoysName'][$i])) { echo '<td>'.$arr['BoysName'][$i].'</td>'; }else{ echo '<td> </td>'; }
if(isset($arr['GirlsName'][$i])) { echo '<td>'.$arr['GirlsName'][$i].'</td>'; }else{ echo '<td> </td>'; }
echo '</tr>';
$i++;
}
Can someone please help?