Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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?

Posted

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.

Posted

Thank you all. Can you tell I'm a database noob? :P

 

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. :yes:

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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