Kristoff1875 Posted July 5, 2012 Share Posted July 5, 2012 I've got a call from a MySQL database that is doing the following: while($info = mysql_fetch_array( $data )) echo '<table width="550" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td width="175" align="right" style="background:#C8E9EB; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC;">Name:</td> <td width="335" align="left" style="background:#C5D7EF; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC; border-right: solid 1px #CCCCCC;">'.$info['name'].'</td> </tr> <tr> <td align="right" style="background:#C8E9EB; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC;">Email:</td> <td align="left" style="background:#C5D7EF; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC; border-right: solid 1px #CCCCCC;">'.$info['email'].'</td> </tr> But i've tried a load of different things, for example: 'if($info['email'] != "") { echo "Yes"; } else { echo "No";}' Just to try and get a different result to show it's working, but every time, whether there is an email or not, it's giving me the same result. Anyone got any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/ Share on other sites More sharing options...
jcbones Posted July 5, 2012 Share Posted July 5, 2012 Try: while($info = mysql_fetch_array( $data )) echo '<table width="550" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td width="175" align="right" style="background:#C8E9EB; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC;">Name:</td> <td width="335" align="left" style="background:#C5D7EF; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC; border-right: solid 1px #CCCCCC;">'.$info['name'].'</td> </tr> <tr> <td align="right" style="background:#C8E9EB; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC;">Email:</td> <td align="left" style="background:#C5D7EF; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC; border-right: solid 1px #CCCCCC;">' . (!empty($info['email']) ? $info['email'] : 'Not Available') . '</td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359312 Share on other sites More sharing options...
Kristoff1875 Posted July 5, 2012 Author Share Posted July 5, 2012 Thanks for that, that works brilliant for displaying a Not Available tag instead of a blank field, but what i'm after really is something I can place before the <tr> tag, to say if it's available, show the next row, if not, then display nothing? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359340 Share on other sites More sharing options...
jcbones Posted July 5, 2012 Share Posted July 5, 2012 It works for that too. But, I was trying to lead you, not feed you. while($info = mysql_fetch_array( $data )) echo '<table width="550" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td width="175" align="right" style="background:#C8E9EB; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC;">Name:</td> <td width="335" align="left" style="background:#C5D7EF; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC; border-right: solid 1px #CCCCCC;">'.$info['name'].'</td> </tr>' . (!empty($info['email']) ? '<tr> <td align="right" style="background:#C8E9EB; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC;">Email:</td> <td align="left" style="background:#C5D7EF; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC; border-right: solid 1px #CCCCCC;">' . $info['email'] . '</td> </tr>' : NULL); Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359373 Share on other sites More sharing options...
Kristoff1875 Posted July 5, 2012 Author Share Posted July 5, 2012 Apologies, i'd not seen the function used in that way before so didn't realise there was an alternative way of using it. Will take a look now, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359377 Share on other sites More sharing options...
Kristoff1875 Posted July 5, 2012 Author Share Posted July 5, 2012 That's brilliant thanks, and worked perfectly apart from..... Anything after the :NULL); code is now removed? Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359384 Share on other sites More sharing options...
jcbones Posted July 5, 2012 Share Posted July 5, 2012 Sorry, didn't know there was more to the string. remove the ; (semicolon), and add a . ' (period, single quote). Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359438 Share on other sites More sharing options...
Kristoff1875 Posted July 5, 2012 Author Share Posted July 5, 2012 Perfect, many thanks. Am I able to manipulate that, for example: ' . (($info['hearabout']) == "Other" ? ' <tr> <td align="right" style="background:#C8E9EB; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC;">Other:</td> <td align="left" style="background:#C5D7EF; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC; border-right: solid 1px #CCCCCC;">' . $info['hearother'] . '</td> </tr>': NULL). ' To show the other details held in "hearother" if "hearabout" is set to other? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359483 Share on other sites More sharing options...
Kristoff1875 Posted July 5, 2012 Author Share Posted July 5, 2012 Just tried that and I think it's working. Thanks for your help. Out of interest, how is it working? Is the (!empty($info['contactother']) ? Basically asking 'contactother' is not empty, and the ? is acting like an if statement for the following code? Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359484 Share on other sites More sharing options...
Barand Posted July 6, 2012 Share Posted July 6, 2012 See ternary operator Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359511 Share on other sites More sharing options...
Kristoff1875 Posted July 6, 2012 Author Share Posted July 6, 2012 That's cool thanks. I understand most of the keys below, I just hadn't ever seen it used as per the example offered. From the comments, it seems to be a shorter way of doing this, is that correct? Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359514 Share on other sites More sharing options...
Kristoff1875 Posted July 6, 2012 Author Share Posted July 6, 2012 One thing that is has been confusing me at the moment is that i'm getting 1 value delivered to the database at certain times that actually has a few spaces, but appears empty: " " but searching to see if it's empty, is not working, as it's not empty! What is the best way to handle this type of value? Is there a way I can check this, or is it something I should do when it's added to the database, to say "if this value doesn't contain.... then value equals blank" ? Or would the trim function work? For anyone looking in, I answered my own question, the trim function did work! Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359515 Share on other sites More sharing options...
Kristoff1875 Posted July 6, 2012 Author Share Posted July 6, 2012 And for anyone else looking in, don't speak too soon! For some reason, one of my fields that was struggling to spot the extra spaces is now hiding fine, but the exact same code on a different value with the same issue, is still not working! :'( Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359517 Share on other sites More sharing options...
Kristoff1875 Posted July 6, 2012 Author Share Posted July 6, 2012 I'm now utterly, utterly confused. On 2 different pages, that pull rows with 2 different ID's, there is 1 field that has an identical value, in the same field. On one page, it doesn't show it. On the other, it does show it... ARGH! Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359520 Share on other sites More sharing options...
jcbones Posted July 6, 2012 Share Posted July 6, 2012 Before adding data to the database, it should be trim'd and then checked for being empty. This way you don't have a bunch of spaces like you are describing. Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359532 Share on other sites More sharing options...
Kristoff1875 Posted July 6, 2012 Author Share Posted July 6, 2012 Yep, i'm going to work on that next! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359533 Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2012 Share Posted July 6, 2012 You should work on that now. It's obviously causing a problem now. When you get all the incoming data trim()med, you can run an UPDATE query to update everything that's already in the database and take care of all of it at once. Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359535 Share on other sites More sharing options...
Kristoff1875 Posted July 6, 2012 Author Share Posted July 6, 2012 When I said next, I meant as in that was the next thing I was going to do on the project! I've done it, and it works! I am very thankful! And luckily, as the project is not yet live, there aren't any meaningful rows in the database yet. Quote Link to comment https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/#findComment-1359538 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.