php - Display data from variables with condition
980
I've a question for you if you can help me, I've some variables that I retrieve with them data from database, but I want to resolve this problemif all the variables are empty then show something if not then show the just the variables that have data
.
The Code is:
foreach ($row as $result) {
if ($row[29] == '') {
$string29 = '';
}else if ($row[29] == 0){
$string29 = '';
} else{
$string29 = '<div ><h1>Pression</h1><img src="images/'.$row[29].'.png"></div>';
}
}
foreach ($row as $result) {
if ($row[30] == '') {
$string30 = '';
}else if($row[30] == 0){
$string30 = '';
} else{
$string30 = '<div ><h1>Fixation</h1><img src="images/'.$row[30].'.png"></div>';
}
}
`
Then I haveecho &string29 and so on........
Answer
Solution:
Your code is rather redundant. By PHP typecasting rules,
0
and''
are actually loosely equal:What you should be doing is have an array of keys/names you could loop over, e.g: