중복으로 표시되지 않도록하기위한 링크입니다.
개발자가 제공 한 솔루션으로 문제를 해결할 수 없었습니다. 이 코드 스 니펫에는 확실히 구문 오류가 있어야하지만 실제로는 아래의 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;
각각에 대해 2 개의 공백이 명확하게 포함 된 공백이 없어야 합니다.
오류보고는 해당 구문 오류를 포착했을 것입니다.
heredoc에서 읽으십시오 :
경고 닫는 식별자가있는 줄에는 세미콜론 (;)을 제외한 다른 문자가 포함되어서는 안됩니다. 이는 특히 식별자가 들여 쓰기되지 않을 수 있으며 세미콜론 앞뒤에 공백이나 탭이 없을 수 있음을 의미합니다. 닫는 식별자 앞의 첫 번째 문자는 로컬 운영 체제에서 정의한 줄 바꿈이어야한다는 사실을 인식하는 것도 중요합니다. 이는 Mac OS X를 포함한 UNIX 시스템에서 \ n입니다. 닫는 구분 기호 뒤에 줄 바꿈이 와야합니다.
각주 :
mysql_*
기능 지원 중단 알림 :
http://www.php.net/manual/en/intro.mysql.php
이 확장은 PHP 5.5.0에서 더 이상 사용되지 않으며 향후 제거 될 예정이므로 새 코드를 작성하는 데 권장되지 않습니다. 대신 mysqli 또는 PDO_MySQL 확장을 사용해야합니다. MySQL API 를 선택하는 동안 추가 도움말 은 MySQL API 개요 를 참조하세요 .
이러한 기능을 사용하면 MySQL 데이터베이스 서버에 액세스 할 수 있습니다. MySQL에 대한 자세한 내용은» http://www.mysql.com/ 에서 찾을 수 있습니다 .
MySQL에 대한 문서는» http://dev.mysql.com/doc/ 에서 찾을 수 있습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다