mysql_fetch_assoc丢失了一个值

i have this code:

function get_team_a($id_team){
    $result = mysql_query("SELECT * FROM `table1` WHERE `id` = '{$id_team}'");
    return mysql_fetch_assoc($result);
}

In table i have 3 columns:

ppl op  id
10  23  1006
6   21  1005
11  15  1004

But when i do that:

$team_zgl= get_team_a($team_id); 
<br><b>'.$team_zgl['id'].' </b>  

i have nothing but this works:

<br><b>'.$team_zgl['op'].' </b>
<br><b>'.$team_zgl['ppl'].' </b>

What the?!

mysql_fetch_assoc() only fetches one row at a time.

$rows = array();
while ($row = mysql_fetch_assoc($result)) {
    $rows[] = $row;
}
return $rows;

This will return a multi-dimensional array of the rows which you can then iterate over.

If not even one row is being returned you probably have a syntax error in your query.


Your code is vulnerable to injection. You should use properly parameterized queries with PDO/mysqli