PHP - 格式不正确

时间:2016-07-28 12:42:22

标签: php html

我目前正在使用PHP教科书来创建电影评论网站,但是,我创建的页面格式不正确,我无法看到我的代码与教科书中的代码之间的区别。这是我创建的页面的屏幕截图: http://imgur.com/a/EBNxk

"日期"应该是一个表格标题旁边"评论家","评论"和"评级"。 "评论"标题也意味着低于电影细节及以上"日期","评论者","评论"和"评级"。该页面的完整代码包含在下面,我知道问题可能在html标签之间,但我只是将它包括在内。

编辑:我现在看到我在第130行留下了一个引号。修复此问题" Date"和它应该是的其他标题一起。但是评论标题仍然高于电影细节。

<?php
function get_director($director_id)
{
    global $db;
    $query = "SELECT people_fullname FROM people WHERE people_id = ". $director_id;
    $result = mysqli_query($db,$query) or die(mysqli_error($db));
    $row = mysqli_fetch_assoc($result);
    extract($row);
    return $people_fullname;
}

function get_leadactor($leadactor_id)
{
    global $db;
    $query = "SELECT people_fullname FROM people WHERE people_id = ". $leadactor_id;
    $result = mysqli_query($db,$query) or die(mysqli_error($db));
    $row = mysqli_fetch_assoc($result);
    extract($row);
    return $people_fullname;
}

function get_movietype($type_id)
{
    global $db;
    $query = "SELECT movietype_label FROM movietype WHERE movietype_id = ". $type_id;
    $result = mysqli_query($db,$query) or die(mysqli_error($db));
    $row = mysqli_fetch_assoc($result);
    extract($row);
    return $movietype_label;
}

function generate_stars($rating)
{
    $stars = " ";
    for($i = 0; $i <= $rating; $i++)
    {
        $stars.= '<img src = "star.png" alt = "star " />';
    }
    return $stars;
}

function calculate_difference($takings,$cost)
{
    $difference = $takings - $cost;

    if($difference<0)
    {
        $color = "red";
        $difference = "$ ".abs($difference)." million";
    }
    else if ($difference > 0)
    {
        $color = "green";
        $difference = "$ ".abs($difference)." million";
    }
    else
    {
        $color = "blue";
        $difference = "$ ".abs($difference)." million";
    }

    return "<span style = \"color:".$color.";\">".$difference."</span>";
}

$db = mysqli_connect('localhost','root') or die('Unable to connect');
mysqli_select_db($db,'moviesite') or die (mysqli_error($db));

$query = "SELECT movie_name, movie_year, movie_director, movie_leadactor,
          movie_type, movie_running_time, movie_cost, movie_takings
          FROM movie
          WHERE movie_id = ".$_GET["movie_id"];
$result = mysqli_query($db,$query);
$row = mysqli_fetch_assoc($result);

$movie_name = $row['movie_name'];
$movie_director = get_director($row['movie_director']);
$movie_leadactor = get_leadactor($row['movie_leadactor']);
$movie_year = $row['movie_year'];
$movie_running_time = $row['movie_running_time']." mins";
$movie_takings = $row['movie_takings']." million";
$movie_cost = $row['movie_cost']." million";
$movie_health = calculate_difference($row['movie_takings'],$row['movie_cost']);

echo <<<ENDHTML
<html>
    <head>
    <title> Details for $movie_name </title>
    </head>

    <body>
    <div style = "text-align:center">
    <h2> $movie_name </h2>
    <h3> Details </h3>
    <table cellpadding = "2" cellspacing = "2" style = "width:70%; margin-left:auto; margin-right:auto">
        <tr>
            <td> <strong> Title </strong></td>
            <td> $movie_name </td>
            <td> <strong> Release Year </strong></td>
            <td> $movie_year </td>
        </tr>
        <tr>
            <td> <strong> Movie Director </strong></td>
            <td> $movie_director </td>
            <td> <strong> Cost </strong></td>
            <td> $movie_cost </td>
        </tr>
         <tr>
            <td> <strong> Lead Actor </strong></td>
            <td> $movie_leadactor </td>
            <td> <strong> Takings </strong></td>
            <td> $movie_takings </td>
        </tr>
        <tr>
            <td> <strong> Running Time </strong></td>
            <td> $movie_running_time </td>
            <td> <strong> Health </strong></td>
            <td> $movie_health </td>
        </tr>
ENDHTML;

$query = 'SELECT review_movie_id, review_date, reviewer_name, review_comment, review_rating
            FROM reviews
            WHERE review_movie_id = '.$_GET['movie_id'] . '
            ORDER BY review_date DESC';
$result = mysqli_query($db, $query) or die(mysqli_error($db));

echo <<<ENDHTML
<h3><em>Reviews</em></h3>
<table cellpadding = "2" cellspacing = "2"
    style = "width:90%; margin-left:auto; margin-right:auto;>
    <tr>
        <th style = "width: 7em"> Date </th>
        <th style = "width: 10em"> Reviewer </th>
        <th> Comments </th>
        <th style = "width: 5em"> Rating </th>
    </tr>
</table>
ENDHTML;

while($row = mysqli_fetch_assoc($result))
{
    $date = $row['review_date'];
    $name = $row['reviewer_name'];
    $comment = $row['review_comment'];
    $rating = generate_stars($row['review_rating']);

    echo <<<ENDHTML
    <td style = "vertical-align: top; text-align:center"> $date </td>
    <td style = "vertical-align: top; text-align:center"> $name </td>
    <td style = "vertical-align: top; text-align:center"> $comment </td>
    <td style = "vertical-align: top; text-align:center"> $rating </td>
    <br/>
ENDHTML;

}

echo <<< ENDHTML

    </div>
    </body>
</html>


ENDHTML;

?>

1 个答案:

答案 0 :(得分:1)

尝试关闭样式上的引号:

localhost