php - 如何在 $row[] 中使用变量的值;在 PHP 中?
问题描述
我不能在 $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);
}
推荐阅读
- c++ - 函数模板参数推导模板参数vs默认模板参数vs返回类型
- google-apps-script - 脚本完成但没有显示任何内容
- nginx - 现有 Nginx 重写规则的表单 url
- html - 在 Visual Studio Code 中输入脚本时我的问题是什么
- r - 如何从嵌套在多级列表中的数据中提取信息?
- visual-studio - 如何调试 C4722 #import 引用了缺失类型库中的类型;'missing-type' 用作占位符
- java - JSON 反序列化器在 REST api @RequestBody 中为 Collection 类型返回“null”
- html - “scroll-snap-type:y 强制”在 Safari 中具有不可见的边距
- python - 我想在python中编写一个函数,如果所有数字都是偶数,则返回true
- python - Swagger with Flask (restx) 中的下拉菜单