-
But I couldn't get your way to work. Could you? I would have used it if it had worked, believe me. I'm not into reinventing the wheel. I don't have time. If you can show me code that works that is better than my simple way, I would be happy to use it. I would have been even happier 2 days ago. But it didn't work!
-
I understand. It would require rewriting more than just that section to make it all fit. As I said, there's nothing wrong with the way you did it. It's the everlasting question of doing it the "elegant" way or doing it this simple and "works" way.
It's all about what saves you the most time-- if you put a lot of work into it right now and do all of that, will it save you time in the end? I don't see any reason why it would. If not, then don't bother. Of course in some cases (like setting up PHP rather than using just HTML files), the extra work clearly is worth it. But here I don't see any reason it would be.
-
Dear Daniel:
I am trying to use your ternary operator and am having trouble. I am trying to output a list of client data (name, address, phone, etc) in table format but I am using css so if the value doesn't exist, the data moves into the wrong column. So I am trying to set the value to a hard space if the value doesn't exist. Perhaps there is a better way to do this (?), but this is what I tried...
Code:
<?php ($client['phone1'] != '')?$client['phone1']:' ';?>
and the whole column disappears. Could you please tell me what did I did wrong? Thanks, e :)
-
Looks like you forgot echo. Aside from that it's right.
Remember-- if the ternary operator is confuses (as it often is), there's no need to use it. If/else works just as well, but it's a little longer to write.
Code:
<?php echo ($client['phone1'] != '')?$client['phone1']:' '; ?>
Also, you might want to use ' ' instead of ' ' because that will actually hold space in the final design. Either will work for the PHP though.
-
Oh, now I understand... thanks! What puzzles me now is that it worked for the first number but as soon as I added the other columns everything disappeared again...
Code:
<div class="col-phone"><?php echo ($client['phone1'] != '')?$client['phone1']:' ';?></div>
<div class="col-phone"><?php echo ($client['phone2'] != '')?$client['phone2']:' ';?></div>
<div class="col-phone"><?php echo ($client['phone3'] != '')?$client['phone3']:' ';?></div>
<div class="col-phone"><?php echo ($client['phone4'] != '')?$client['phone4']:' ';?></div>
It doesn't make logical sense to me that the additional lines would make the first line stop working. Thanks so much for your help. :)
-
Not sure about that. Perhaps you had a trailing echo from the last section?... not sure if that's likely.
-
Sorry, it turns out it does work, but the email address is wrapping to the 2nd line so it looked wrong. I need to work on the formatting more it seems. Sorry to bother you unnecessarily. I REALLY appreciate your help! You are a saint. :)