【发布时间】:2015-07-19 14:08:33
【问题描述】:
这是为了避免被标记为重复的链接
按照开发人员提供的解决方案,我无法解决问题。在这段代码的 sn-p 中肯定存在语法错误,但我找不到它在哪里,事实上,下面的 Heredoc 语句不起作用并阻止整个代码工作,此外,如果我尝试运行我的网络服务器上的代码我有一个 500 服务器错误。我已经修改了我的问题,将答案纳入其中。
在编辑这个问题之前,我尝试自己解决问题,但我走到了死胡同。我刚刚在代码开头添加了错误报告,即使重新打开旧问题不是很正确。
<?php error_reporting(E_ALL); ini_set('display_errors', 1);?>
<?php
// take in the id of a director and return his/her full name
function get_director($director_id) {
global $db;
$query = 'SELECT
people_fullname
FROM
people
WHERE
people_id = ' . $director_id;
$result = mysql_query($query, $db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $people_fullname;
}
// take in the id of a lead actor and return his/her full name
function get_leadactor($leadactor_id) {
global $db;
$query = 'SELECT
people_fullname
FROM
people
WHERE
people_id = ' . $leadactor_id;
$result = mysql_query($query, $db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $people_fullname;
}
// take in the id of a movie type and return the meaningful textual
// description
function get_movietype($type_id) {
global $db;
$query = 'SELECT
movietype_label
FROM
movietype
WHERE
movietype_id = ' . $type_id;
$result = mysql_query($query, $db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $movietype_label;
}
//connect to MySQL
$db = mysql_connect('localhost', 'root', 'xxxxxxxx') or
die ('Unable to connect. Check your connection parameters.');
// make sure you’re using the right database
mysql_select_db('moviesite', $db) or die(mysql_error($db));
// retrieve information
$query = 'SELECT
movie_name, movie_year, movie_director, movie_leadactor,
movie_type
FROM
movie
ORDER BY
movie_name ASC,
movie_year DESC';
$result = mysql_query($query, $db) or die(mysql_error($db));
// determine number of rows in returned result
$num_movies = mysql_num_rows($result);
$table = <<<ENDHTML
<div style="text-align: center;">
<h2>Movie Review Database</h2>
<table border="1" cellpadding="2" cellspacing="2"
style="width: 70%; margin-left: auto; margin-right: auto;">
<tr>
<th>Movie Title</th>
<th>Year of Release</th>
<th>Movie Director</th>
<th>Movie Lead Actor</th>
<th>Movie Type</th>
</tr>
ENDHTML;
/* loop through the results */
while ($row = mysql_fetch_assoc($result)) {
extract($row);
$director = get_director($movie_director);
$leadactor = get_leadactor($movie_leadactor);
$movietype = get_movietype($movie_type);
$table .= <<<ENDHTML
<tr>
<td>$movie_name</td>
<td>$movie_year</td>
<td>$director</td>
<td>$leadactor</td>
<td>$movietype</td>
</tr>
ENDHTML;
}
$table.= <<<ENDHTML
</table>
<p>$num_movies Movies</p>
</div>
ENDHTML;
echo $table;
?>
> this is the error that I receive
ENDHTML; /* loop through the results */ while ( = mysql_fetch_assoc(Resource id #3)) { extract(); = get_director(); = get_leadactor(); = get_movietype();
.= << ENDHTML; }
【问题讨论】:
-
为避免被视为重复,您可以链接到您发现的类似问题,但该问题的答案对您不起作用。
-
另外,人们需要查看错误的内容以便帮助您 =]
-
`ENDHTML;` 看起来像
ENDHTML;之前的 2 个空格 -
为什么要使用heredoc?只需在 html 之前结束 php 并在循环之前启动它
-
您使用“我的修复”编辑了您的问题,关于您的 heredoc 中的空格,但没有将其标记为编辑。请不要那样做。人们会访问该问题并查看您的新代码和我的答案并说:“那里没有空格,那么为什么要回答?” - 反过来可能会否决我的答案。我回滚到你原来的帖子。