我正在为学校创建一个小项目。我已经能够创建一个完成工作查询的函数(使用SQL测试)。
我得到的错误是;注意:尝试在第34行的E:\ programs \ XAMPP \ htdocs \ Esports \ View \ Tournament.php中获取非对象的属性'tournamentName'。
但是我为他们所有人做到了这一点?不知道为什么。
如果有人可以提供帮助,我将不胜感激。
我的代码如下。
我的DataAccess.php运行查询的函数是;
function getAllTourament()
{
global $pdo;
$statement = $pdo ->prepare (' SELECT tournament.tournamentName,
tournament.console,
tournament.no_of_players,
tournament.prize,
game.gName,
sponsors.sponsorName,
venue.venue_name,
venue.venue_location,
venue.venue_date,
venue.venue_time
FROM tournament, game, sponsors, venue
WHERE tournament.gameID = game.gameID AND tournament.sponsorID = sponsors.sponsorID AND tournament.venueID = venue.venueID
ORDER by tournament.tournamentName, console, no_of_players, prize , gName , sponsorName , venue_name,venue_location, venue_date, venue_time');
$statement->execute();
$result = $statement;
return $result;
}
调节器
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
require_once ("../Model/dataAccess.php");
require_once ("../Model/Game.php");
require_once ("../Model/Tournament.php");
require_once ("../Model/Sponsor.php");
require_once ("../Model/Venue.php");
$allTournament = getAllTourament();
//$allTournament = getAllT();
查看Tournament.php
<?php
require_once ("../Controller/allTournament.php");
?>
<?php
require "header.php";
?>
<main>
<table>
<thead>
<tr>
<th>Tournament Name</th>
<th>Console</th>
<th>No Of Players</th>
<th>Prize</th>
<th>Game Name </th>
<th>Sponsor Name </th>
<th>Venue Name </th>
<th>Venue Location </th>
<th>Venue Date </th>
<th>Venue time </th>
</tr>
</thead>
<tbody>
<tr> <?php foreach ($allTournament as $Tview): ?>
<td><?= $Tview-> tournamentName ?> </td>
<td><?= $Tview-> console ?> </td>
<td><?= $Tview-> no_of_players ?> </td>
<td><?= $Tview-> prize ?> </td>
<td><?= $Tview-> gName ?> </td>
<td><?= $Tview-> sponsorName ?> </td>
<td><?= $Tview-> venue_name ?> </td>
<td><?= $Tview-> venue_location ?> </td>
<td><?= $Tview-> venue_date ?> </td>
<td><?= $Tview-> venue_time ?> </td>
</tr><?php endforeach ?>
</tbody>
</table>
</main>
<?php
require "footer.php";
?>
模特Tournament.php
class Tournament {
// private $gameId;
private $tournamentName;
private $console;
private $no_of_players;
private $prize;
/* magic getter and setter */
function __get($name)
{
return $this->$name;
}
function __set ($name, $value)
{
$this->$name = $value;
}
}
模型Game.php
class Game {
// private $gameId;
private $gName;
private $rating;
private $genre;
private $price;
private $date;
/* magic getter and setter */
function __get($name)
{
return $this->$name;
}
function __set ($name, $value)
{
$this->$name = $value;
}
}
型号Venue.php
class Venue {
// private $id;
private $venue_name;
private $venue_location;
private $venue_time;
private $venue_date;
private $venue_seats;
/* magic getter and setter */
function __get($name)
{
return $this->$name;
}
function __set ($name, $value)
{
$this->$name = $value;
}
}
模特Sponsor.php
class Sponsor
{
private $sponsorName;
private $sponsorWsite;
private $sponsorType;
private $sponsorLength;
function __get($name) {
return $this->$name;
}
function __set($name, $value) {
$this->$name = $value;
}
}