Jump to content

Hide if db field is empty


vikingbear_ds

Recommended Posts

Hi, using php and mySQL

I am trying to hide items in a list if the field is empty in the database, this function has worked in teh past, but in this case the <li> is still displaying on the page..

 <?php if ($totalRows_rsOsprey > 0) { // Show if recordset not empty ?>
  <li><a><?php echo $row_rsOsprey['tour_header_08']; ?></a></li>
  <?php } // Show if recordset not empty ?>

ANy suggestions?

Regards, Ken

 

 

Link to comment
https://forums.phpfreaks.com/topic/278573-hide-if-db-field-is-empty/
Share on other sites

Hi Guru,

I should probably mention that the <li> is part of a JQUERY tab system,
I tried to 'hide' one of the <div> statements as well..
What do you mean by 'What is $totalRows_rsOsprey set to?' are you thinking field type in database?

 

 

<ul>
<?php if ($totalRows_rsOsprey > 0) { // Show if recordset not empty ?>
  	<li><a><?php echo $row_rsOsprey['tour_header_02']; ?></a></li>
  <?php } // Show if recordset not empty ?>
  <?php if ($totalRows_rsOsprey > 0) { // Show if recordset not empty ?>
    <li><a><?php echo $row_rsOsprey['tour_header_03']; ?></a></li>
    <?php } // Show if recordset not empty ?>
  <?php if ($totalRows_rsOsprey > 0) { // Show if recordset not empty ?>
    <li><a><?php echo $row_rsOsprey['tour_header_04']; ?></a></li>
    <?php } // Show if recordset not empty ?>
  <?php if ($totalRows_rsOsprey > 0) { // Show if recordset not empty ?>
    <li><a><?php echo $row_rsOsprey['tour_header_05']; ?></a></li>
    <?php } // Show if recordset not empty ?>
  <?php if ($totalRows_rsOsprey > 0) { // Show if recordset not empty ?>
    <li><a><?php echo $row_rsOsprey['tour_header_06']; ?></a></li>
    <?php } // Show if recordset not empty ?>
  <?php if ($totalRows_rsOsprey > 0) { // Show if recordset not empty ?>
    <li><a><?php echo $row_rsOsprey['tour_header_07']; ?></a></li>
    <?php } // Show if recordset not empty ?>
  <?php if ($totalRows_rsOsprey > 0) { // Show if recordset not empty ?>
  <li><a><?php echo $row_rsOsprey['tour_header_08']; ?></a></li>
  <?php } // Show if recordset not empty ?>
</ul>
			<div>
				<div><?php echo $row_rsOsprey['tour_text_02']; ?></div>
        		<div><?php echo $row_rsOsprey['tour_text_03']; ?></div>
				<div><?php echo $row_rsOsprey['tour_text_04']; ?></div>
        		<div><?php echo $row_rsOsprey['tour_text_05']; ?></div>
				<div><?php echo $row_rsOsprey['tour_text_06']; ?></div>
        		<div><?php echo $row_rsOsprey['tour_text_07']; ?></div>
                <?php if ($totalRows_rsOsprey > 0) { // Show if recordset not empty ?>
  <div><?php echo $row_rsOsprey['tour_text_08']; ?></div>
  <?php } // Show if recordset not empty ?>
            </div>

Hi Gury,
I should also have explained that I am a coding novice.. :)
I tried <?php echo $row_rsOsprey['tour_header_08']; var_dump($tour_header_08); ?>

and got an error in the browser ;

PHP Notice:  Undefined variable: tour_header_08 in C:\inetpub\wwwroot\2013.downunderdive.com.au\osprey_v_cruise.php on line 609

Hey Nerbie, Your if condition is:

 

$totalRows_rsOsprey > 0

 

You say the li still prints? Then $totalRows_rsOsprey must be greater than 0.

 

Your code literally makes no sense though. You could put all of that within the same loop. But really you should probably look into normalizing your data and using loops.

Solved it, (and looking back it makes sense) Thanks for everybody's time and input!

 

<?php if ($totalRows_rsOsprey['tour_header_08'] > 0) { // Show if recordset not empty ?>
  <li><a><?php echo $row_rsOsprey['tour_header_08']; ?></a></li>
  <?php } // Show if recordset not empty ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.