这是链接,以避免被标记为重复
根据开发人员提供的解决方案,我无法解决问题。在这段代码中肯定存在语法错误但我无法找到它的位置,事实上下面的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; }
&#13;
答案 0 :(得分:2)
在结束标识符enum
之前不应该有任何空格,它们每个明显包含2个空格。
错误报告会捕获该语法错误。
阅读heredoc:
警告强> 请注意,除了分号(;)之外,具有结束标识符的行必须不包含其他字符,这一点非常重要。这尤其意味着标识符可能没有缩进,并且在分号之前或之后可能没有任何空格或制表符。同样重要的是要认识到结束标识符之前的第一个字符必须是本地操作系统定义的换行符。这是在UNIX系统上的\ n,包括Mac OS X.结束分隔符后面也必须跟一个换行符。
<强>脚注:强>
ENDHTML;
函数弃用通知:
http://www.php.net/manual/en/intro.mysql.php
从PHP 5.5.0开始,不推荐使用此扩展,不建议用于编写新代码,因为将来会删除它。相反,应使用mysqli或PDO_MySQL扩展名。在选择MySQL API时,另请参阅MySQL API Overview以获得进一步的帮助。
这些功能允许您访问MySQL数据库服务器。有关MySQL的更多信息,请访问»http://www.mysql.com/。
可以在»http://dev.mysql.com/doc/找到MySQL的文档。
答案 1 :(得分:1)
怎么样
$num_movies = mysql_num_rows($result);
?><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>
<?php /* 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);
echo "<tr><td>$movie_name</td><td>$movie_year</td><td>$director</td><td>$leadactor</td><td>$movietype</td></tr>";
}
echo "</table><p>$num_movies Movies</p></div>";
?>