【发布时间】:2014-03-05 09:15:10
【问题描述】:
我正在尝试为从我的查询返回的每一行运行一个 while 循环,同时打印一个包含所有垂直列值的数组?到目前为止,这是我的代码,虽然我不确定如何实现数组。
问题是我不希望在 while 循环中包含每个列值的数组。基本上我试图显示每个数据库行值的 html 表行。所以我已经在 while 循环的行中显示了值,但是如何访问数据的垂直列并将其显示为我的代码中的数组以创建图形。
代码中也有注释..
<?php
mysql_select_db("db_name", $con);
$qry = "SELECT * FROM tbl_name WHERE col_name='$col_name'";
$result = mysql_query($qry);
if (!$result) exit("The query didnt succeded");
else {
<!-- my while loop using each individual row from the database -->
while ($row = mysql_fetch_array($result)) {
$col1 = $row['col-name1'];
$col2 = $row['col-name2'];
$col3 = $row['col-name3'];
$col4 = $row['col-name4'];
$col5 = $row['col-name5'];
include 'file_to_be_looped.php';
?>
<br/>
<br/>
<?php
}
}
?>
<!-- then just get a list of all values from a single column of the same query-->
<?php echo $col1 ?> <!--this echo produces the last value in the array, so I think im close-->
【问题讨论】:
标签: php mysql arrays while-loop