如何在 php 中使用 $row[] 中的变量值?

  • 本文关键字:变量值 row php php sql
  • 更新时间 :
  • 英文 :


我不能在 $row[] 中使用变量;

$a = id

然后当我这样做时:

$sql = "SELECT * FROM articles WHERE ID='$id'";
$result5 = mysqli_query($link, $sql);
if (mysqli_num_rows($result5) > 0)
{
while($row = mysqli_fetch_assoc($result5))
{
$aa = $row[$a];
}
}

然后当我

echo $aa

我没有得到预期的结果。 然后$aa应该返回像 193 这样的值,因为这是 id 列中的值。这是

$aa = $row[$a]; 

似乎不起作用的部分。

使用array_push().请参阅此处的文档

array_push($row, $a)

在您的代码中应用它:

$sql = "SELECT * FROM articles WHERE ID='".$id."'";
$result5 = mysqli_query($link, $sql);
if (mysqli_num_rows($result5) > 0)
{
while($row = mysqli_fetch_assoc($result5))
{
$aa = $row[];
array_push($aa, $a)
}
print_r($aa);
}

最新更新