Question

could someone give me a hint here, because I am trying to resolve the problem I have for some time, and I am getting nowhere for now.

I have one while loop which is listing all players from one team, and need to list their statistics. I tried with nested while loop, but I am not getting any results printed.

<?php 
while($player=mysql_fetch_array($var2)) {
    echo $player[1] ." ". $player[2] ." ". $player[3] ." ". $player[4] ." "; 
    $goal=mysql_query("SELECT A.Minute+A.Minuteadditional from Appearance A 
    where A.Type=1 and A.Appearance_ID in (Select M.ID_Matches from Matches M 
    where M.Player_ID=$player[0] and M.Match_ID=$match)",$connection);

    while($g=mysql_fetch_array($goal)) {
        echo $g[0] .", ";
    }
    echo "<br>"; 
}
?>

Here I tried to get all minutes when specific player scored (printed on right from his name). Query has results in phpMyadmin, but code returns no results here.

$player[0] is a player ID, and rest of fields are shirt number, last name, surname etc... I know that having query inside a loop is not recommended, but I am still beginner with php and this way looks to me the most logical and easier to understand.

Was it helpful?

Solution

if you using

$player[1] ." ". $player[2] ." ". $player[3] ." ". $player[4]

then i guess you should use mysql_fetch_row instead.

then your code will be

 while($player=mysql_fetch_row($var2)) {

Try this

<?php 
 $player=mysql_fetch_row($var2);

 $goal=mysql_query("SELECT A.Minute+A.Minuteadditional from Appearance A 
 where A.Type=1 and A.Appearance_ID in (Select M.ID_Matches from Matches M 
 where M.Player_ID = $player[0] and M.Match_ID = $match)",$connection);

 while($g=mysql_fetch_row($goal)) {
echo $g[0] .", ";
}

?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top