I am looking for a programming shortcut. I want to push the entire row into an associative array, the $key being the same as the column name, and the $value being the value in that particular column, and all that, one row at a time.

我正在寻找一个编程快捷方式。我想将整行推入一个关联数组,$ key与列名相同,$ value是该特定列中的值,所有这一行,一次一行。

So far, the only way I know how to do something like this is:

到目前为止,我知道如何做这样的事情的唯一方法是:

$array = [];
$push_item = [];

while ($row = $result->fetch_assoc())
{
     $column_name_1 = $row['column_name_1'];
     $column_name_2 = $row['column_name_2'];
     //etc.

   $push_item = ["column_name_1" => $column_name_1, "column_name_2" => $column_name_2, ];
   array_push($array, $push_item);
}

And like that, for every row in the table.

就像那样,对于表中的每一行。

I am looking for a solution that will go easier on my typing. Can I grab the column names and data automatically?

我正在寻找一种解决方案,在打字时会更容易。我可以自动获取列名和数据吗?

Thank you.

谢谢。

1 个解决方案

#1


1

Found it myself:

自己找到了:

The function that does this is $mysqli->fetch_array();

执行此操作的函数是$ mysqli-> fetch_array();

更多相关文章

  1. 在ajax中接收php多维数组。
  2. 查找具有特定数据字符串的数组并返回其具有的另一个数据字符串
  3. 使用PHP读取特定XML节点上特定数组的值
  4. 从数组中回显键和值
  5. Laravel将动态输入数据数组保存到数据库中
  6. 在多维数组中查找最小值并返回键
  7. 如何使用变量访问多维数组中的某些元素?
  8. 键入提示 - 指定对象数组
  9. 切出多维数组的一部分

随机推荐

  1. 父范围中的变量不会在匿名函数中被更改[
  2. 如何避免pro拖拉机中的“jasmin .suite()
  3. 如何验证一个大表格
  4. 在迭代完成之前,回调会触发
  5. Knockout.js - 在通过observable设置值
  6. 依据parentId动态构建一颗树
  7. [JavaScript]自执行函数
  8. 如何更改我的按钮文字?
  9. jQuery方向感知悬停与CSS3过渡
  10. JavaScript学习07 内置对象