首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PDO,如何查看来自4个不同表的选定数据,然后使用PHP在网页上查看这些数据

PDO,如何查看来自4个不同表的选定数据,然后使用PHP在网页上查看这些数据
EN

Stack Overflow用户
提问于 2019-03-12 03:28:13
回答 1查看 54关注 0票数 1

我正在为学校创建一个小项目。我已经能够创建一个函数来完成一个工作查询(使用SQL测试)。

我得到的错误是;注意:试图在第34行的E:\programs\XAMPP\htdocs\Esports\View\Tournament.php中获取非对象的属性'tournamentName‘。

但是我给他们所有人都做了这个?不知道为什么。

如果有人能帮忙,我将不胜感激。

我的代码如下。

我运行查询的DataAccess.php函数是;

代码语言:javascript
复制
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;   
}

控制器

代码语言:javascript
复制
    <?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

代码语言:javascript
复制
  <?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

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
class Sponsor 
{
    private $sponsorName;
    private $sponsorWsite;       
    private $sponsorType;
    private $sponsorLength;
                function __get($name) {
        return $this->$name;
    }

    function __set($name, $value) {
        $this->$name = $value;
    }



}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55109030

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档