Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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 从mysqli结果中读取值_Php_Mysql_Object_Mysqli_Fetch - Fatal编程技术网

Php 从mysqli结果中读取值

Php 从mysqli结果中读取值,php,mysql,object,mysqli,fetch,Php,Mysql,Object,Mysqli,Fetch,我试图从mysqli查询中读取比较值,但未成功 这是我的代码示例: $sql = "SELECT team, won, lost, points, goals_for, goals_agn FROM teaminfo WHERE tour_id=5 ORDER BY points DESC, (goals_for - goals_agn) DESC, goals_for DESC ;"; $query = $this->db_connection->query($sql); 因此,

我试图从mysqli查询中读取比较值,但未成功

这是我的代码示例:

$sql = "SELECT team, won, lost, points, goals_for, goals_agn FROM teaminfo WHERE tour_id=5 ORDER BY points DESC, (goals_for - goals_agn) DESC, goals_for DESC ;";
$query = $this->db_connection->query($sql);
因此,这是一个简单的sql查询,我从teaminfo数据库中获取所有球队,并希望根据某些标准(分数、得分…)对它们进行比较,以确定哪支球队将进入下一阶段的比赛

使用类似循环的方式打印所有值非常简单:

while ($team=mysqli_fetch_array($query)) {... some code ...}
但是我不需要这个。我只想访问其中的几个,并对它们进行比较。例如:

//Compare 3rd team points from $query with 4th team points from $query
     If ($team[3]['points']==$team[4]['points']) 
{
       I would do something..

    } else ....

我只需要“transform”$query,这样我就可以手动使用其中的所有数据。我尝试了从php.net获取数据,但正如我所说的,都没有成功。

您可以将所有数据放在一个数组中,然后再使用它

$teams = array();
while ($team=mysqli_fetch_array($query)) {
  $teams[$team['team']] = $team;
}
然后您可以通过
$teams['teamname']

if($teams['teamA']['points'] == $teams['teamB']['points']){
    // do something
}

它可以直接使用

 $teams[] = $team;

来填充数组。但我建议使用关联填充,因为这样可以更容易地访问团队的数据。如果要使用特定团队的数据,只需输入一个数字,您就必须检查他们的姓名。

是的,我完全忘记了填充数组。Thx:)