boxturt Posted February 22, 2005 Posted February 22, 2005 Greetings. I have returned with yet another maybe-not-so-odd question. ... I have a working database table with 20+ fields in it. Due to the nature of the information submitted only about half of these will have content in any given unique row. I can connect and display the entire contents but as you may imagine it looks pretty ridiculous with half the fields missing. I'd like to be able to display ONLY fields that have something in them, not empty ones (geez - I am so far over my head). I've tried adding conditions and I am not doing it right. Here's a snippet of what does work (only a few fields though) : ><? $dbuser = ""; $dbserver = "localhost"; $dbpass = ""; $dbname = ""; mysql_connect($dbserver, $dbuser, $dbpass) or die ("UNABLE TO CONNECT TO DATABASE"); mysql_select_db($dbname) or die ("UNABLE TO SELECT DATABASE"); $sql = "SELECT * FROM mydata"; $result = mysql_query($sql); if ($myrow = mysql_fetch_array($result)) { do { $first_name=$myrow["first_name"]; $last_name=$myrow["last_name"]; $phone=$myrow["phone"]; $email=$myrow["email"]; $website=$myrow["website"]; $comments=$myrow["comments"]; echo "<BR>Name: $first_name"; echo " $last_name"; echo "<BR>Phone: $phone"; echo "<BR>Email: $email"; echo "<BR>Website: $website"; echo "<BR>Comments: $comments"; echo "<BR><BR>"; } while ($myrow = mysql_fetch_array($result)); } ?> Any suggestions? I've been looking and looking, reading and reading and I'm just not getting it. Perhaps I need to redo the whole thing as maybe this is a bad way to even start to do this. Any guidance is always greatly appreciated. Thank you. Quote
TCH-RobertM Posted February 22, 2005 Posted February 22, 2005 While I am not fully clear on what you are trying to accomplish, I did find this Page to be similar to what your doing. It may help you. Quote
HCSuperStores Posted February 22, 2005 Posted February 22, 2005 I don't know how you'd do it in PHP, but in Perl you would do this: >if(length($phone)>0) { print "<BR>Phone: $phone"; } Hope that helps! Bill Quote
TCH-Bruce Posted February 22, 2005 Posted February 22, 2005 I think it would look something like this. >if ($phone != "") { echo "<BR>Phone: $phone"; } Quote
boxturt Posted February 22, 2005 Author Posted February 22, 2005 Thank you, I will try. At the moment my site is not responding but I'll let you know. Quote
boxturt Posted February 22, 2005 Author Posted February 22, 2005 Thanks Bruce! That did it and I could/should kick myself. I had it before - forgot the ( ) grrrrrr One last thing - are email addresses susceptible to bots when displayed like this? Thanks again. Quote
TCH-Don Posted February 22, 2005 Posted February 22, 2005 Ty if the e-mail can be seen when you view the source code of the finished page, then spam bots will be able to see them. Quote
owatagal Posted February 22, 2005 Posted February 22, 2005 Unless your pages are password protected and/or you use forms instead of displaying email address, the bots can almost certainly pick up the addresses. It's difficult if not impossible to display an email address to your visitors in such a way that a bot can't pick it up. But you can make life more difficult--munging the address can help: >if ($email != "") { $email = trim($email); $email = preg_replace("/@/", " [at ] ", $email); $email = preg_replace("/\./", " [dot] ", $email); echo "<br>Email: $email"; } I haven't tested the code, but in theory it should work. Well, if I got the regular expressions right. This should output: Email: username [at] domain [dot] ext Alternatively, you can use hex encode to "hide" the address from bots while displaying it to visitors -- see PHP's bin2hex function (http://uk2.php.net/bin2hex). But bots can figure that out as well as (better than?) munging. Personally I use munging, with non-standard phrases (i.e. not [at] or [dot], both of which are easy to guess and look for from the spammer's perspective). Neither method is fool-proof, but either is better than nothing, you know? Quote
HCSuperStores Posted February 22, 2005 Posted February 22, 2005 I use javascript ... and that seems to work well: $email = 'me'+'@'+'mydomainname'+'.'+'c'+'om'; document.write($email); You can even hex code the whole thing too ... but you generally don't have to go that far. Quote
boxturt Posted February 22, 2005 Author Posted February 22, 2005 Thank you all. Can you tell I'm a database noob? Yes Don, I should have realised that - thanks for the reminder. owatagal, HC - I will try the munging as I'm not sure I could get php + javascript to play nice together. I really appreciate all the help. Quote
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.