Forums
This topic is locked
hide empty fields when using PHP and MySQL
Posted 25 Feb 2003 12:46:50
1
has voted
25 Feb 2003 12:46:50 Mick Warnes posted:
HiI have a problem with a database I am writing to store personnel and their car details.
This is fine if they have one car, but many people have at least 2, maybe 3, and I want these to appear on different lines (so not to effect the width of the table)
In each repeated region, there are 3 rows, the 2nd and 3rd are used to cope with the 2nd and 3rd car.
I have tried a few methods to get these additional rows to hide if these fields are empty using the existing MX server behaviours.
I have also tried this with the 2nd and 3rd details in the same cell using break to simulate them on different rows, but without success.
I think this requires a bit more cunning, any help will be most appreciated.
Mick
Replies
Replied 25 Feb 2003 14:54:53
25 Feb 2003 14:54:53 Brent Colflesh replied:
Dear Mick,
In your car field repeat, encapsulate your field display code with an if... statement, ie:
<?php if ($rsRecordDetail->Fields("cars"<>"" { ?>
Regards,
Brent
In your car field repeat, encapsulate your field display code with an if... statement, ie:
<?php if ($rsRecordDetail->Fields("cars"<>"" { ?>
Regards,
Brent
Replied 28 Feb 2003 10:46:57
28 Feb 2003 10:46:57 Julio Taylor replied:
make sure you also close the repeat with <?php } ?> after the <TD> or <TR> that you are affecting...
------------------------
Julio
PHP | MySQL | DWMX | ColdFusion
ICQ: 19735247
------------------------
Julio
PHP | MySQL | DWMX | ColdFusion
ICQ: 19735247
Replied 04 Mar 2003 17:55:28
04 Mar 2003 17:55:28 Mick Warnes replied:
Thanks for the replies, I'm new at this and probably need a bit more assistance. Where in the following should this code go?
<pre id=code><font face=courier size=2 id=code>
<table width="500" border="1">
<tr>
<td>Name</td>
<td>Department</td>
<td>Job Title</td>
<td>ext</td>
<td>Car</td>
<td>Reg</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rsPersonnel['firstName']; ?> <?php echo $row_rsPersonnel['lastName']; ?></td>
<td><?php echo $row_rsPersonnel['department']; ?></td>
<td><?php echo $row_rsPersonnel['jobTitle']; ?></td>
<td><?php echo $row_rsPersonnel['ext']; ?></td>
<td><?php echo $row_rsPersonnel['vehicle1']; ?></td>
<td><?php echo $row_rsPersonnel['reg1']; ?></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><?php echo $row_rsPersonnel['vehicle2']; ?></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><?php echo $row_rsPersonnel['vehicle3']; ?></td>
<td> </td>
</tr>
<?php } while ($row_rsPersonnel = mysql_fetch_assoc($rsPersonnel)); ?>
</table>
</font id=code></pre id=code>
Thanks again
<pre id=code><font face=courier size=2 id=code>
<table width="500" border="1">
<tr>
<td>Name</td>
<td>Department</td>
<td>Job Title</td>
<td>ext</td>
<td>Car</td>
<td>Reg</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rsPersonnel['firstName']; ?> <?php echo $row_rsPersonnel['lastName']; ?></td>
<td><?php echo $row_rsPersonnel['department']; ?></td>
<td><?php echo $row_rsPersonnel['jobTitle']; ?></td>
<td><?php echo $row_rsPersonnel['ext']; ?></td>
<td><?php echo $row_rsPersonnel['vehicle1']; ?></td>
<td><?php echo $row_rsPersonnel['reg1']; ?></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><?php echo $row_rsPersonnel['vehicle2']; ?></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><?php echo $row_rsPersonnel['vehicle3']; ?></td>
<td> </td>
</tr>
<?php } while ($row_rsPersonnel = mysql_fetch_assoc($rsPersonnel)); ?>
</table>
</font id=code></pre id=code>
Thanks again
Replied 04 Mar 2003 18:27:25
04 Mar 2003 18:27:25 Brent Colflesh replied:
Dear Mick,
Around each field you are echoing that could be empty - ex:
<td>
<?php if ($row_rsPersonnel['department']<>"" { ?>
<?php echo $row_rsPersonnel['department']; ?>
<? }?>
</td>
Regards,
Brent
Around each field you are echoing that could be empty - ex:
<td>
<?php if ($row_rsPersonnel['department']<>"" { ?>
<?php echo $row_rsPersonnel['department']; ?>
<? }?>
</td>
Regards,
Brent