Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 有没有一种方法可以通过索引而不是命名来访问行和列?_Php - Fatal编程技术网

Php 有没有一种方法可以通过索引而不是命名来访问行和列?

Php 有没有一种方法可以通过索引而不是命名来访问行和列?,php,Php,我的密码是 $sql = "SELECT * FROM user_buildings WHERE player_id = '$id'"; $result = mysqli_query($conn, $sql); $amounts = array(); while ($row = $result->fetch_assoc()) {

我的密码是

                $sql = "SELECT * FROM user_buildings WHERE player_id = '$id'";
                $result = mysqli_query($conn, $sql);
                $amounts = array();
                while ($row = $result->fetch_assoc()) {
                    $amounts[0] = $row['cursor_amount'];
                    $amounts[1] = $row['grandma_amount'];
                }
但是,我希望能够做到的是,不要像我在这里那样命名列“cursor\u amount”和“grandma\u amount”,而是执行以下操作:

                $sql = "SELECT * FROM user_buildings WHERE player_id = '$id'";
                $result = mysqli_query($conn, $sql);
                $amounts = array();
                while ($row = $result->fetch_assoc()) {
                    $amounts[0] = $row[0];
                    $amounts[1] = $row[1];
                }
虽然当我尝试这样做时,我收到了未定义的偏移量错误。 任何帮助都将不胜感激,是的,我已经尝试寻找答案了。我不太清楚我需要哪些关键术语来让我的搜索更加具体,因此如果这个问题的答案已经存在,我很抱歉,如果是这样的话,请随意发布指向正确答案的链接,而不是自己解释。

使用以下链接获取结果:

$result->fetch_数组(MYSQLI_NUM)

使用以下命令获取结果:


$result->fetch_数组(MYSQLI_NUM)

是的,您可以使用
$result->fetch_array(MYSQLI_NUM)
@AlexJBallz为什么要访问具有名称而不是名称的列?使用数字可以得到什么?@Progman,它允许我编写更少的代码,因为现在我可以在循环中分配所需的每个变量。是的,你可以使用
$result->fetch_array(MYSQLI_NUM)
@AlexJBallz为什么要访问列,这些列有名称,而不是名称?使用数字能得到什么?@Progman,它允许我编写更少的代码,因为现在我可以在循环中分配所需的每个变量。