adrianle Posted August 18, 2009 Share Posted August 18, 2009 I'm pulling a record from mySQL to display on a page. I need to write something so that if a particular field (say, Address2) is empty in the recordset, to hide the other wise displayed field value on the page. Help? Quote Link to comment https://forums.phpfreaks.com/topic/170906-how-to-hide-code-pieces/ Share on other sites More sharing options...
Aeolus Posted August 18, 2009 Share Posted August 18, 2009 I'm sure there's a more efficient way to do this, but maybe you could do a set of if statements (if field1 is blank echo all but field1).. if I'm understanding you correctly.. ? Quote Link to comment https://forums.phpfreaks.com/topic/170906-how-to-hide-code-pieces/#findComment-901411 Share on other sites More sharing options...
oni-kun Posted August 18, 2009 Share Posted August 18, 2009 Like this? .. if (!empty($address1) || !empty($address2)) { echo "Here they are.... $address1 + $address2"; } else { //do nothing, or display a warning that one is blank. } Quote Link to comment https://forums.phpfreaks.com/topic/170906-how-to-hide-code-pieces/#findComment-901414 Share on other sites More sharing options...
adrianle Posted August 18, 2009 Author Share Posted August 18, 2009 Thanks for the help.. that defnitely helped with the address question.. now, how would I modify this so that if the email field is blank, then the page just skips that line and goes to the next value? Like this? .. if (!empty($address1) || !empty($address2)) { echo "Here they are.... $address1 + $address2"; } else { //do nothing, or display a warning that one is blank. } Like this? .. if (!empty($address1) || !empty($address2)) { echo "Here they are.... $address1 + $address2"; } else { //do nothing, or display a warning that one is blank. } Quote Link to comment https://forums.phpfreaks.com/topic/170906-how-to-hide-code-pieces/#findComment-901436 Share on other sites More sharing options...
roopurt18 Posted August 18, 2009 Share Posted August 18, 2009 oni-kun gave you most of what you need. If you look real carefully at how you phrased your original question and how he provided his answer, you just might be able to figure out what you need to change to get it to work... Quote Link to comment https://forums.phpfreaks.com/topic/170906-how-to-hide-code-pieces/#findComment-901441 Share on other sites More sharing options...
oni-kun Posted August 18, 2009 Share Posted August 18, 2009 now, how would I modify this so that if the email field is blank, then the page just skips that line and goes to the next value? if (!isset($_POST['e-mail']) || !empty($_POST['e-mail'])) { $e-mail = $_POST['e-mail']; } Basically like that, so it'll only list or assign the e-mail variable if it is not empty in the database, if it is empty then it'll skip the code completely. Quote Link to comment https://forums.phpfreaks.com/topic/170906-how-to-hide-code-pieces/#findComment-901442 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.