Hi - I have a table in a php page where these are the first two rows:
<tr>
<td><span class="style2">Artist</span></td>
</tr>
<tr>
<td><span class="style8">
<?php if ($totalRows_rsRecRes > 0) { // Show if recordset not empty ?>
<?php echo $row_rsRecordings['recordingartistName']; ?>
<?php } // Show if recordset not empty ?></span></td>
</tr>
basically what I want to be able to do is to hide the header (Artist) if the database field that should populate the second row (recordingartistName) is empty. Is it possible to do this in PHP and if so, could some good samaritan show me using the above code how I'd go about doing it, please? I'd be forever grateful. Thanks.
Can someone tell me if this is even possible?
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Can someone tell me if this is even possible?
Just move the if statement up before the Artist row:
Code: Select all
<?php if ($totalRows_rsRecRes > 0) { // Show if recordset not empty
?>
<tr>
<td><span class="style2">Artist</span></td>
</tr>
<tr>
<td><span class="style8">
<?php echo $row_rsRecordings['recordingartistName'];?>
</span></td>
</tr>
<?php } // Show if recordset not empty
?>mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Can someone tell me if this is even possible?
Thanks for the suggestion, but that didn't do it - the header still displays, and there's a blank space where the field detail should go...
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Can someone tell me if this is even possible?
Try printing the table only if $totalRows_rsRecRes > 0 :
Code: Select all
<?php if ($totalRows_rsRecRes > 0) {
echo '<table>';
// rest of your code
echo '</table>';
}
else {
// something to indicate no record
} ?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Can someone tell me if this is even possible?
Thanks, but I got a parse error when I tried that...
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Can someone tell me if this is even possible?
That doesn't mean the idea is incorrect, it means there is an error with the code. Please paste the problematic code.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering