我有一个MySQL表,我用左连接运行查询:
//Select Datenbankanfrage, erste Zeile
function first($query, $restype=0) {
$this->querystring = $query;
if ( $restype==1 ) $restype=MYSQLI_ASSOC;
else $restype=MYSQLI_BOTH;
$result = $this->query($query); //Query
if ( !$result ) return false;
$row = $result->fetch_array($restype);
$result->free();
return $row;
}
使用此功能:
array
但我收到一个1 => Maxii
Name => Maxii
2 => Streetfromthe
Street => Streetfromthe
,其中包含密钥作为回复:
{{1}}
如何禁用键(1,2)或如何在数组中删除它?
这是从完整数组返回的Nopaste: https://nopaste.xyz/?23ccf318bbfc93fb#Oes85/9Z8+Kookk2nTLmbtObjaL8mD2aitPPrHV3v9w=
答案 0 :(得分:1)
问题来自$ restype,你的第二个参数。它默认为零,它将使用MYSQLI_BOTH,它通过索引和名称返回字段。你当然想要一个关联数组(MYSQLI_ASSOC),将$ restype传递给1。
负责更改重定型的行是:
if ( $restype==1 ) $restype=MYSQLI_ASSOC;
else $restype=MYSQLI_BOTH;
答案 1 :(得分:0)
您需要将$result->fetch_array
替换为$result->fetch_assoc
编辑:在您的情况下,将其保留在fetch_array并使用您拥有的功能。
使用first($sql, 1);