Can someone tell me if this is even possible?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
moomin52
Forum Newbie
Posts: 3
Joined: Mon Mar 08, 2010 10:37 am

Can someone tell me if this is even possible?

Post by moomin52 »

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.
User avatar
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?

Post by AbraCadaver »

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.
moomin52
Forum Newbie
Posts: 3
Joined: Mon Mar 08, 2010 10:37 am

Re: Can someone tell me if this is even possible?

Post by moomin52 »

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...
User avatar
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?

Post by social_experiment »

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
moomin52
Forum Newbie
Posts: 3
Joined: Mon Mar 08, 2010 10:37 am

Re: Can someone tell me if this is even possible?

Post by moomin52 »

Thanks, but I got a parse error when I tried that...
User avatar
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?

Post by social_experiment »

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
Post Reply