Jump to content

Hide if db field is empty


vikingbear_ds
Go to solution Solved by 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
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>
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Solution

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 ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.