PHP World cup score board

so my ploblem is i dont know how to show a scorebord like example Argentina vs Belgium and Brazil vs Germany, Like the away team vs home team, can you help? (p.s = i am from belgium so the code is mixed with dutch, i hope its oke.)

Wedstrijd.php= Controller

include_once  "model/wedstrijd.class.php";
$db = include_once "db.php";
$wedstrijdInstance = new Wedstrijd($db);

$alleWedstrijden = $wedstrijdInstance->getAllWedstrijden();

$output = include_once "views/list-wedstrijden-form.php";

return $output;

wedstrijd.class.php = model

class Wedstrijd{
    private $db;
    
    public function __construct($dbConnection){
        $this->db = $dbConnection;
    }
    public function getAllWedstrijden(){
        $query = "SELECT thuisploeg.naam as thuisploegNaam, uitploeg.naam as uitploegNaam, scoreUit, scoreThuis
        from wedstrijd, ploeg as thuisploeg, ploeg as uitploeg
        where thuisId = thuisploeg.ploegId
        and uitId = uitploeg.ploegId";
        $statement = $this->db->prepare($query);
        $statement->execute();  
        return $statement->fetchAll(PDO::FETCH_CLASS);
    }
}
_____

list-wedstrijd-form = view

    $outputStr ="<ul class='list-group'> <li class='list-group-item active'>Wedstrijden</li>";
    foreach ($alleWedstrijden as $wedstrijd){ 
        $outputStr .="

            <li class='list-group-item'>
                $wedstrijd->thuisploegNaam - $wedstrijd->uitploegNaam   |  $wedstrijd->scoreUit - $wedstrijd->scoreThuis 
            </li>

             ";
     }
     $outputStr .=  "</ul>";
        return($outputStr);

this my sql database

What is the specific problem? That is, what does your code produce that is incorrect / not what you need?

I’d have thought you would need to do an INNER JOIN in your query, to retrieve the team names.

i only get this, there is no - (and the other team)

image

when i change something nothing happend so what i did is i copy everything in a new map under a new name with the same codes, but now i get a error, for me this a next step becaus now i know it wil work after i fix this error but i do not understand this error

That means you got an error within your PDO instance. You can easily debug this by doing a var_dump($this); and having a look at the $db variable. You see it’s not an object? So you can’t use any method on it. But you will most likely just get bool false or something, so you have to go further doing more var_dumps in the constructor and getting further to where you call the class. Does your “db.php” really return an instance of PDO? Otherwise you can’t assign it to a variable. You can also ensure to always get an instance of PDO with public function __construct(PDO $dbConnection){ ....

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.