There is a code:

prin<<<HERE <table border="0" width="250px" style=" position:absolute; top:140px; left:350px; display: inline-block; white-space:normal;"> <tr> <td> <p style=" font-size:25px; padding-left: px;">$myrowd[name]</p> <hr> <h style=" padding-top:10px; padding-left: px;">$reg</h><br> <hr> <h style=" padding-top:10px; padding-left: px;">$myrowd[textar]</h><br> <hr> <h style=" padding-top:10px; padding-left: px;">$myrowd[textaus]</h><br> <hr> <p style=" padding-top:10px; padding-left: px;">$myrowd[number]</p> </td> </tr> </table> HERE; 

User data is displayed in variables. I need to do the following: if the field (for example, textar ) in the database is empty, then this is:

  <h style=" padding-top:10px; padding-left: px;">$myrowd[textar]</h><br> <hr> 

not displayed. How to do this? I assume that it is possible with the help of if, but I don’t know how to put a piece of code in a variable, but surely it will be ugly.

  • Specify somehow the last part of the question, otherwise I’ve reread for the fifth time, but I can’t convert everything into some kind of logical chain. I’m getting old, but ...)) - Deonis

2 answers 2

Maybe it will do:

 <?php if(isset($myrowd[textar] && $myrowd[textar] == null || $myrowd[textar] == "")){ $string_textar = '<h style=" padding-top:10px; padding-left: px;">$myrowd[textar]</h><br>/n<hr>'; } else { $string_textar = '<h style=" padding-top:10px; padding-left: px;">$myrowd[textar]</h><br>'; } print<<<HERE <table border="0" width="250px" style=" position:absolute; top:140px; left:350px; display: inline-block; white-space:normal;"> <tr> <td> <p style=" font-size:25px; padding-left: px;">$myrowd[name]</p> <hr> <h style=" padding-top:10px; padding-left: px;">$regreg</h><br> <hr> $string_textar <hr> <h style=" padding-top:10px; padding-left: px;">$myrowd[textaus]</h><br> <hr> <p style=" padding-top:10px; padding-left: px;">$myrowd[number]</p> </td> </tr> </table> HERE; ?> 

    Something like this:

     $string="<table border='0' width='250px' style=' position:absolute; top:140px; left:350px; display: inline-block; white-space:normal;'><tr><td>"; foreach($myrowd as $key => $value){ if($value!=""){ $string.="<h style=' padding-top:10px; padding-left: px;'>$value</h><br><hr>"; } } $string.="</td></tr></table>"; echo $string; 

    Go around the array, check it for the existence of variables.
    If the variable is, then we form the HTML code and enter it into a string.
    Then we display the string in the browser.

    • Well, you check the existence, there are all variables, it will output everything! For from the database everything is dragged, and the empty variable is also a variable! - Artem
    • I agree. Tupanul. Corrected. - zenith