0

好的,我将解释我正在做一个电影在线预订系统...用户可以选择电影->电影院->要预订的放映我已经到达放映页面

这是查找特定电影和电影院节目的代码:

<?php
require('classes/show_class.php');
$show=new show($_GET["cinema_id"]);  //CAN I MAKE 2 GETS LIKE THIS?? MAYBE THIS
$show=new show($_GET["movie_id"]);   // IS THE ERROR

$showcinemas = $show->get_show_cinemas();


    echo '<table border="1">';
    echo '<tr><td align="center"><b>CINEMA<b></td></tr>';

foreach ($showcinemas as $show)
{
    $show_id = $show['show_id'];
    $show_datetime = $show['show_datetime'];
    $cinema_id = $show['cinema_id'];
    $movie_id = $show['movie_id'];

    echo '<tr>';
    echo '<td>';
    echo "<a href='show_theater.php?cinema_id={$cinema_id}&movie_id={$movie_id}&show_id={$show_id}'>" . $show_datetime . '</a>';
    echo '</td>';
    echo '</tr>';

}
    echo '</table>';
?>

此页面的输出是:CINEMA 2013-03-03 14:00:00 <-- 这是cinema_id=1&movie_id=1&show_id=1 虽然我使用过movie_id=2&cinema_id=5

我希望我现在说清楚了……谢谢你

这是 show_class.php

public function __construct()
{


    $query = mysql_query(
            "SELECT *
            FROM movie, cinema
            "
        );

    $results = mysql_fetch_assoc($query);

    $this->movie_id = $results['movie_id'];
    $this->movie_name = $results['movie_name'];
    $this->movie_category = $results['movie_category'];
    $this->cinema_id = $results['cinema_id'];
    $this->cinema_name = $results['cinema_name'];
}


public function get_show_cinemas()
{
    $query = mysql_query(
        "SELECT show.show_datetime, show.show_id, cinema.cinema_id, movie.movie_id
    FROM `cinema`
    JOIN `theater` ON `theater`.`cinema_id` = `cinema`.`cinema_id`
    JOIN  `show` ON  `show`.`theater_id` =  `theater`.`theater_id` 
    JOIN `movie` ON `movie`.`movie_id` =  `show`.`movie_id`
    WHERE  `cinema`.`cinema_id` = {$this->cinema_id} AND `movie`.`movie_id` = {$this->movie_id} "
    );

    while( $cinema =  mysql_fetch_assoc( $query ) )
    {
        $results[] = $cinema;
    }

    return $results;        
}
4

2 回答 2

3

你的表演类只需要初始化一次。尝试将其他参数(cinema_id 和 movie_id)设为类的成员变量或将它们传递给类构造函数。

  class show {
    public function __construct($cinema_id, $show_id) { //do work }
  }

或者

  class show {
     public $cinema_id, $show_id;
     public function __construct() { }
     public function setCinemaId($cinema_id)
     {
       $this->cinema_id = $cinema_id;
     }
     public function setShowId($show_id)
     {
       $this->show_id = $show_id;
     }
     public function fetchShowCinemas()
     {
       if(!empty($this->show_id) && !empty($this->cinema_id)) { //do work }
     }
  }

然后

  $show = new show();
  $show->setCinemaId($_GET['cinema_id']);
  $show->setShowId($_GET['show_id']);
  $showCinemas = $show->fetchShowCinemas();
于 2013-04-03T17:53:44.967 回答
1

您需要更新 Show 类的构造函数以接受这些值作为参数,或者在类实例化后包含用于设置这些变量的函数。

class Show {
    public $cinemaId;
    public $movieId;

    public function __construct($cinemaId, $movieId)
    {
        this->cinemaId = $cinemaId;
        this->movieId = $movieId;
    }

    public function __construct() { }

    public function setCinemaId($cinemaId)
    {
      $this->cinemaId = $cinemaId;
    }

    public function setMovieId($movieId)
    {
      $this->movieId= $movieId;
    }

    public function getShows() 
    {
       // do work  
    }
}

您需要转义这些值以防止 SQL 注入:

$cinemaId = mysql_real_escape_string($_GET['cinema_id'])
$movieId = mysql_real_escape_string($_GET['movie_id'])

方法一:

$show = new Show($cinemaId, $movieId);
$show->getShows();

方法B:

$show = new Show();
$show->setCinemaId($cinemaId);
$show->setMovieId($movieId);
$show->getShows();
于 2013-04-03T18:01:20.257 回答