how many if else can use ??
<?php if($d_1 == 'null') { ?> <td align="center"><input type="date" name="clas1" /><br/><input id="class1" type="submit" name="c1" value="submit" /></td> <?php } else { ?> <td align="center"><span>completed on <br/> <?php echo $d_1;?></span> </td> <?php } if($d_2 == 'null') { ?> <td align="center"><input type="date" name="clas2" /><br/><input id="class2" type="submit" name="c2" value="submit" /></td> <?php } else { ?> <td align="center"><span>completed on <br/> <?php echo $d_2;?></span> </td> <?php } if($d_3 == 'null') { ?> <td align="center"><input type="date" name="clas3" /><br/><input id="class3" type="submit" name="c3" value="submit" /></td> <?php } else { ?> <td align="center"><span>completed on <br/> <?php echo $d_3;?></span> </td> <?php } if($d_4 == 'null') { ?> <td align="center"><input type="date" name="clas4" /><br/><input id="class4" type="submit" name="c4" value="submit" /></td> <?php } else { ?> <td align="center"><span>completed on <br/> <?php echo $d_4;?></span> </td> <?php } ?>
i fetching 4 dates database are: $d_1, $d_2, $d_3 & $d_4. checking each date if-else condition. first 2 conditions working fine in 3rd , 4th condition else part being executed other way ??? thanks..
you can making simple function:
<?php function fun($val,$num) { if(empty($val) || $val == 'null' || $val == 'null') { echo '<td align="center"><input type="date" name="class'.$num.'" /><br/><input id="class'.$num.'" type="submit" name="c'.$num.'" value="submit" /></td>'; } else { echo '<td align="center"><span>completed on <br/>'.$val.'</span></td>'; } } fun($d_1,"1"); fun($d_2,"2"); fun($d_3,"3"); fun($d_4,"4"); ?>
by using approach can check multiple dates.
Comments
Post a Comment