Copy link to clipboard
Copied
Hi all. I have a page of listings pulled from a database which uses the standard "show region is recordset is not empty" server behaviour. This is working fine and if there's no content for a particular field, then this behaviour does what it's supposed to do.
Problem is that each element of the listing has a header (title/name/description...etc etc) and I want to hide the header for any field that doesn't have any content.
OK, I know I can include the header in the table listing and then it would either show or not, depending, but ideally I need to be able to style the header differently from the listing text, and if it's coming in as {rsArtists.artName}
Copy link to clipboard
Copied
<?php if ($row_featured_art['art_caption']!= "") { ; ?>
<?php echo $row_featured_comp['art_caption']; ?>
<?php } else { };?>
The above could be used with a bit more modification to do what you want.
if the field is NOT empty then show the field
Else show nothing
Copy link to clipboard
Copied
I'm pretty basic with php so bear with me, if you will - could this be modified to apply so that if I have this:
header1
element1
header2
element2
etc etc
that I can use this to stop header1 from showing if element1 is an empty record? Is that what you mean?
Copy link to clipboard
Copied
Yes.
If I give you an example:
Im not sure how you are making this
but something like this
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<?php if ($query['heading1'] != "") {?><th scope="col">Header 1</th><?php } else { };?>
<th scope="col">Header 2</th>
</tr>
<tr>
<td>bob</td>
<td>joe</td>
</tr>
</table>
you will need a row cound somewhere
Copy link to clipboard
Copied
Basically the table I've got looks like this:
<table>
<tr>
<td><span class="style2">Artist</span></td>
</tr>
<tr>
<td><span class="style8">
<?php if ($totalRows_DetailRS1 > 0) { // Show if recordset not empty ?>
<?php echo $row_DetailRS1['specialPersonName']; ?>
<?php } // Show if recordset not empty ?></span></span></td>
</tr>
<tr>
<td><span class="style2">Title</span></td>
</tr>
<tr>
<td><span class="style8">
<?php if ($totalRows_DetailRS1 > 0) { // Show if recordset not empty ?>
<?php echo $row_DetailRS1['specialTitle']; ?>
<?php } // Show if recordset not empty ?></span></span></td>
</tr>
</table>
If you could show me how to apply your code suggestion to the first one of those, I'd really appreciate it.
Copy link to clipboard
Copied
Ok the idea is to enclose the part of the table you want to show if there is a record for it.
<table>
<?php if ($row_DetailRS1['specialPersonName'] != "") { ?>
<tr>
<td><span class="style2">Artist</span></td>
</tr>
<tr>
<td><span class="style8">
<?php if ($totalRows_DetailRS1 > 0) { // Show if recordset not empty ?>
<?php echo $row_DetailRS1['specialPersonName']; ?>
<?php } // Show if recordset not empty ?></span></span></td>
</tr>
<?php } else { } ;?>
<?php if ($row_DetailRS1['specialTitle'] != "") { ?>
<tr>
<td><span class="style2">Title</span></td>
</tr>
<tr>
<td><span class="style8">
<?php if ($totalRows_DetailRS1 > 0) { // Show if recordset not empty ?>
<?php echo $row_DetailRS1['specialTitle']; ?>
<?php } // Show if recordset not empty ?></span></span></td>
</tr>
<?php } else { } ;?>
</table>
PS sorry for my short previous post, was at work. :'( You wont need a row count of any kind.
Copy link to clipboard
Copied
Just tried that and it's exactly what I was looking for, thank you so much, really appreciate it. I clearly need to get myself a decent book on PHP to get my head round all this clever stuff like IF ELSE and so on - any recommendations?
Copy link to clipboard
Copied
David Powers has a great book.
http://foundationphp.com/
Copy link to clipboard
Copied
I'm trying to make sense of this whole IF ELSE thing and have knocked up a small table with the following code:
<table width="100%">
<?php if ($row_rsFrontpage['frontpage'] !== "n") { ?><tr>
<td width="22%" rowspan="4" valign="top"><a href="specialDetails.php?recordID=<?php echo $row_rsFrontpage['specialID']; ?>"><img src="images/<?php echo $row_rsFrontpage['smallphoto']; ?>" alt="" name="smallpic" border="0" id="smallpic" /></a></td>
<td width="78%" class="style3"><?php if ($totalRows_rsFrontpage > 0) { // Show if recordset not empty ?>
<?php echo $row_rsFrontpage['specialTitle']; ?>
<?php } // Show if recordset not empty ?></td>
</tr>
<tr>
<td><?php if ($totalRows_rsFrontpage > 0) { // Show if recordset not empty ?>
<?php echo $row_rsFrontpage['specialDescription']; ?>
<?php } // Show if recordset not empty ?></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><strong>THIS IS AN UNBEATABLE AUCTION PRIZE! </strong><a href="specialDetails.php?recordID=<?php echo $row_rsFrontpage['specialID']; ?>">More></a></td>
</tr><?php } else { } ;?>
</table>
The field 'frontpage' in the database is set to ENUM with 'y','n' as the possible options. Ideally what I'm trying to do is get this working so that if the listing has 'n' it doesn't show in this table, if it has a 'y' it does, but when I test it locally it either serves up the first listing in the table (there are only two for test purposes) or shows nothing if I change the value from "n". I'd appreciate some guidance on how to get this to work. Thanks in advance.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more