这是我的代码:
$resultNew = $conn->query("SELECT getal FROM telling where tel = 'yes' group by getal order by getal");
while($rowNew = mysqli_fetch_array($resultNew))
{
$rowsArrawNew[] = $rowNew;
}
foreach($rowsArrawNew as $value)
{
echo "<TD>".$value. "</TD>";
}
问题是:输出为: Array Array Array Array ,而不是我期望的 2 5 29 58 。
提前谢谢!
答案 0 :(得分:0)
当mysqli_fetch_array()
返回一个列值数组时-即使只有1个值,当您将其添加到其中时
$rowsArrawNew[] = $rowNew;
$rowsArrawNew
将是一个数组数组。要只获取您后面的值1,您可以更改任一部分以从数组中提取值...
$rowsArrawNew[] = $rowNew['getal'];
或
echo "<TD>".$value['getal']. "</TD>";
(但不能同时使用)。
答案 1 :(得分:0)
您可以使用提取功能或关联数组, mysqli_fetch_array()返回关联数组...
$resultNew = $conn->query("SELECT getal FROM telling where tel = 'yes' group by getal order by getal");
while($rowNew = mysqli_fetch_array($resultNew))
{
$rowsArrawNew[] = $rowNew;
}
foreach($rowsArrawNew as $value)
{
extract ($value);
echo "<TD>".$getal. "</TD>";
}
或关联数组
$resultNew = $conn->query("SELECT getal FROM telling where tel = 'yes' group by getal order by getal");
while($rowNew = mysqli_fetch_array($resultNew))
{
$rowsArrawNew[] = $rowNew;
}
foreach($rowsArrawNew as $value)
{
echo "<TD>".$value['getal']. "</TD>";
}
正在工作的您都想做一个