Set default value in while loop using Php Mysqli -
i'm new mysqli object oriented style , i'm trying set default value if no info database category.
this i've got far
'r8 0 1.0' should in r8 column
my code:
<tr> <td><?php echo $name; ?></td> <td><?php echo $inv; ?></td> <?php $stmtprod = $db -> prepare("select riou.riou_pr_code, riou.riou_boughtcase, riou.riou_boughtbottle retail_items_ou riou inner bring together products pr on (riou.riou_pr_id = pr.pr_id) inner bring together products_extent pe on (riou.riou_pr_id = pe.pe_pr_id) riou.riou_rinou_id = ? , pr.pr_category = '8 oz' order pe.pe_individualarrange"); $stmtprod -> bind_param('i',$id); $stmtprod -> execute(); $stmtprod -> bind_result($code,$case,$bot); while($test = $stmtprod -> fetch()){ if($test === null){ echo '<td>default value</td>'; }else{ echo '<td>'.$code.' '.$case.'.'.$bot.'</td>'; } } $x++; ?> </tr>
output should this:
the if statment not working. give thanks you
i'd run check see if (for example) code equals 0 (which presume if sql returns empty field). if does, set variable different.
$code = ($code == 0) ? "default value" : $code;
do each item wish double-check has value. if dislike ternary's, of course of study standard if case.
if(!$code) { $code = "default value"; }
php mysqli
No comments:
Post a Comment