Forums

PHP

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:
Hi

I 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



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
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>
&lt;table width="500" border="1"&gt;
&lt;tr&gt;
&lt;td&gt;Name&lt;/td&gt;
&lt;td&gt;Department&lt;/td&gt;
&lt;td&gt;Job Title&lt;/td&gt;
&lt;td&gt;ext&lt;/td&gt;
&lt;td&gt;Car&lt;/td&gt;
&lt;td&gt;Reg&lt;/td&gt;
&lt;/tr&gt;
&lt;?php do { ?&gt;
&lt;tr&gt;
&lt;td&gt;&lt;?php echo $row_rsPersonnel['firstName']; ?&gt; &lt;?php echo $row_rsPersonnel['lastName']; ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_rsPersonnel['department']; ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_rsPersonnel['jobTitle']; ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_rsPersonnel['ext']; ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_rsPersonnel['vehicle1']; ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_rsPersonnel['reg1']; ?&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_rsPersonnel['vehicle2']; ?&gt;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_rsPersonnel['vehicle3']; ?&gt;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;?php } while ($row_rsPersonnel = mysql_fetch_assoc($rsPersonnel)); ?&gt;

&lt;/table&gt;
</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:

&lt;td&gt;
&lt;?php if ($row_rsPersonnel['department']&lt;&gt;"" { ?&gt;
&lt;?php echo $row_rsPersonnel['department']; ?&gt;
&lt;? }?&gt;
&lt;/td&gt;

Regards,
Brent

Reply to this topic