Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/265238-hiding-table-row-of-empty-values/
Share on other sites

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>

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

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);
  

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

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?

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!

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!  :'(

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!

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.