php - 如何在循环外显示数组变量
问题描述
你好我有这样的代码
<div class="table-wrapper-2">
<!--Table-->
<table class="table table-striped">
<thead class="mdb-color lighten-4">
<tr>
<th>#</th>
<th class="th-lg">Name</th>
<th class="th-lg">Surname</th>
<th class="th-lg">Country</th>
<th class="th-lg">City</th>
<th class="th-lg">Position</th>
<th class="th-lg">Age</th>
<th class="th-lg">Position</th>
<th class="th-lg">Position</th>
</tr>
</thead>
<tbody>
<?php
$a='TAJUL';
$stid = oci_parse($conn, 'SELECT def_usr,problem,solution,def_date,closed_date FROM hd_report where def_usr=:num order by def_date DESC');
oci_bind_by_name($stid, ":num", $a);
oci_execute($stid);
$count = 0;
while (($row = oci_fetch_row($stid)) != false) {
$def_usr=$row[0];
$problem=$row[1];
$solution=$row[2];
$def_date=$row[3];
$closed_date=$row[4];
$count=$count+1;
?>
<tr>
<th scope="row"><?php echo $count ?></th>
<td><?php echo $def_usr ?></td>
<td><?php echo $def_date ?></td>
<td><?php echo $closed_date ?></td>
<td><?php echo $problem ?></td>
<td>
<button type="button" href="#myModalDelete"
data-toggle="modal" class="btn btn-danger"
data-problem="<?php $problem?>">
<span class="glyphicon glyphicon-trash"></span>Detail
</button>
</td>
<?php
}
?>
</tr>
</tbody>
</table>
<!--Table-->
</div>
</div>
</div>
<!-- Start Modal for Delete -->
<div id="myModalDelete" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title">Alert message !!!</h4>
</div>
<div class="modal-body">
<!-- The form is placed inside the body of modal -->
<form method="post" action="view_detailquestion">
<h3>Are you sure you want to View this question ?</h3>
<div class="form-group">
<label>ID</label> <input type="text" class="form-control"
name="problem" value="<?php echo $problem?>" readonly>
</div>
<button type="submit" class="btn btn-danger" name="action"
value="view">view</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
我的问题是我想在循环外回显 $problem。当我这样做时,它只包含 1 个值。所以我想有什么解决方案可以让我在括号外解决 $problem。就像我们都可以在启动模式中看到的那样对于删除,我尝试回显 $problem 但结果很喜欢我说只携带 1 个值而不是数组......所以我希望你们可以成为我的向导,谢谢......
解决方案
像这样:
$problem=array();
while (($row = oci_fetch_row($stid)) != false) {
$problem[]=$row[1];
}
foreach($var in $problem){
echo $var . "<br />"
}
推荐阅读
- sql - 从数据中创建列
- verilog - 为什么 systemverilog 断言属性中不鼓励“if..else”语句?
- html - 我们如何根据其内容调整父元素的高度?
- javascript - 如何更改侧边栏和标题的免费 React.js 管理模板中的 coreUi 徽标?
- django - 在 django 中创建自定义值方法
- windows - 当从同一 Windows CMD shell 中运行时,DOSKEY 宏会中断批处理脚本的提示 (SET /P)
- scala - NoSuchMethodError:com.google.common.hash.Hashing.crc32c
- pandas - 添加 2 列具有不同日期的时间序列数据框
- amazon-s3 - 在 Boto3 中使用 SES 从 S3 存储桶发送带有附件的电子邮件
- python - 在 CMD 中运行 Python