vikingbear_ds Posted May 29, 2013 Share Posted May 29, 2013 Hi, using php and mySQLI 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 29, 2013 Share Posted May 29, 2013 What is $totalRows_rsOsprey set to? Quote Link to comment Share on other sites More sharing options...
vikingbear_ds Posted May 29, 2013 Author Share Posted May 29, 2013 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> Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 29, 2013 Share Posted May 29, 2013 *smh* what is the value? What makes you think the code isn't working? Quote Link to comment Share on other sites More sharing options...
vikingbear_ds Posted May 30, 2013 Author Share Posted May 30, 2013 Hi Gury..http://2013.downunderdive.com.au/osprey_v_cruise.phpYou can see the last TAB is still showing althought there is no data fed from database.. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 30, 2013 Share Posted May 30, 2013 Registered member, echo the variable and see what's actually in it. var_dump Quote Link to comment Share on other sites More sharing options...
vikingbear_ds Posted May 30, 2013 Author Share Posted May 30, 2013 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 Quote Link to comment Share on other sites More sharing options...
dannon Posted May 30, 2013 Share Posted May 30, 2013 (edited) <?php var_dump($row_rsOsprey); echo $row_rsOsprey['tour_header_08']; ?> Try this ^ instead. Edited May 30, 2013 by dannon Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 30, 2013 Share Posted May 30, 2013 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. Quote Link to comment Share on other sites More sharing options...
Solution vikingbear_ds Posted May 30, 2013 Author Solution Share Posted May 30, 2013 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 ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.