Var转储结果
我将MySQL中的数据提取到HTML表格中:
<div id="toggleDiv" class="">
<div class="box-body" id="toggleDiv_2">
<div class="row">
<div class="col-md-6">
<?php
$select_patient_info_cash =
"SELECT * FROM patient_info WHERE id_logged = :id_logged".
" AND patient_id = :patient_id AND payment_type = :pt";
$select_patient_info_cash_stmt =
$conn->prepare($select_patient_info_cash);
$select_patient_info_cash_stmt->bindValue(":id_logged", $id_logged);
$select_patient_info_cash_stmt->bindValue(":patient_id", $patient_id);
$select_patient_info_cash_stmt->bindValue(":pt", "cash");
$select_patient_info_cash_stmt->execute();
$select_patient_info_cash_stmt->fetch(PDO::FETCH_ASSOC);
$select_patient_info_cash_stmt_count =
$select_patient_info_cash_stmt->rowCount();
if($select_patient_info_cash_stmt_count > 0){ ?>
<table style="text-align:center"
class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Project Description</th>
<th>Project Cost</th>
<th>Date Of Pay</th>
</tr>
</thead>
<?php foreach ($select_patient_info_cash_stmt as $cash) { ?>
<tr>
<td><?php echo $cash['project'] ?></td>
<td><?php echo $cash['project_cost'] ?></td>
<td><?php echo $cash['date_now'] ?></td>
</tr>
<?php } ?>
</table>
<?php } else { ?>
<?php } ?>
</div><!-- /.col -->
现在,我为患者信息中包含payment_type != cash
,<thead>
未显示的数据的用户进行测试。但是,当我在payment_type=cash
<thead>
显示<thead>
时,但没有数据回显到行中。
它应该在dialog.setOnDissmissListener(){
void onDismiss(){
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
inputManager.hideSoftInputFromInputMethod(getCurrentFocus().getWindowToken(), 0);
}
}
dialog.dismiss();
之后显示2个新行,我无法弄清楚为什么数据不会显示在页面上
答案 0 :(得分:3)
我想你在准备好的陈述中错过了->fetch()
。根据PHP文档:
<?php
$stmt = $dbh->prepare("SELECT * FROM REGISTRY where name = ?");
if ($stmt->execute(array($_GET['name']))) {
while ($row = $stmt->fetch()) {
print_r($row);
}
}
?>
因此,您需要将代码修改为:
<?php while ($cash = $select_patient_info_cash_stmt->fetch()) { ?>
<tr>
<td><?php echo $cash['project'] ?></td>
<td><?php echo $cash['project_cost'] ?></td>
<td><?php echo $cash['date_now'] ?></td>
</tr>
<?php } ?>
我还建议您使用MVC框架或某种模板引擎。混合PHP和HTML是一种非常糟糕的做法。