php – SELECT query not working properly or what im doing wrong-ThrowExceptions

Exception or error:

Helo all, im having troubles with SELECT query in my php code, if someone could help me to see what im doing wrong that would be great.
when im queryng direct from phpmyadmin it shows me all rows, but when im queryin from php it sown only first two, its really strange.

phpmyadmin query screenshot:

enter image description here

Showing rows 0 – 24 (32 total, Query took 0.0007 seconds.)

here is my php code:

$sql = ("SELECT * FROM `amx_match_half` WHERE `team1_id`=" . $team_id . " OR `team2_id`=" . $team_id);
$half_query = mysqli_query($link, $sql) or die("Cannot query the database: " . mysqli_error($link));

$matches_won = 0;
$matches_lost = 0;

while( $half_data = mysqli_fetch_array($half_query))
{
    $half_id = $half_data['half_id'];
    echo "$half_id <br>";
    // Get matches that the team played in
    $sql = "SELECT * FROM `amx_match_main` WHERE `half1_id`=" . $half_id;
    $match_query = mysqli_query($link, $sql) or die("Cannot query the database: " . mysqli_error($link));

    $team1_score = 0;
    $team2_score = 0;

    if ($match_data = mysqli_fetch_array($match_query))
    {
        for($i = 1; $i < 9; $i++)
        {
            // Pull the neccesary stuff from the match row
            $half_id = $match_data["half" . $i . "_id"];
            if( $half_id != -1 )
            {
                // Get team_id's from half_id
                $sql = "SELECT * FROM `amx_match_half` WHERE `half_id`=" . $half_id;
                $half_query = mysqli_query($link, $sql) or die("Cannot query the database: " . mysqli_error($link));
                $half_data = mysqli_fetch_array($half_query);

                if( $i % 2 == 0 )
                {
                    $team2_score += $half_data['team1_score'];
                    $team1_score += $half_data['team2_score'];
                }
                else
                {
                    $team1_score += $half_data['team1_score'];
                    $team2_score += $half_data['team2_score'];
                }

            }
        }

        // Pull the neccesary stuff from the half row
        $half_id = $match_data["half1_id"];

        // Get team_id's from half_id
        $sql = "SELECT * FROM `amx_match_half` WHERE `half_id`=" . $half_id;
        $half_query = mysqli_query($link, $sql) or die("Cannot query the database: " . mysqli_error($link));
        $half_data = mysqli_fetch_array($half_query);

        $team2_id = $half_data['team2_id'];

        if ( $team2_id == $team_id )
        {
            $temp = $team1_score;
            $team1_score = $team2_score;
            $team2_score = $temp;
        }


        if( $team1_score > $team2_score )
        {
            $matches_won++;
        }
        else
        {
            $matches_lost++;
        }
    }
}

result from echo "$half_id <br>";

15 81
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *