PDA

View Full Version : unexpected $end



Sepax1
دوشنبه 04 شهریور 1392, 16:23 عصر
سلام به همه دوستان .

من یه کد دارم که این ایراد unexpected $end رو میگیره . 2 ساعتم چکش کردم . مشکلش پیدا نشد .

اگه کسی می دونه مشکلش چیه بگه . ممنون .



<?php
include 'forum_inc.php';
database();

$select_topic = "SELECT topic_id , topic_owner , topic_title ,
DATE_FORMAT(topic_create_time , '%b %e %Y at %r') AS
topic_time FROM forum_topics
ORDER BY topic_time DESC ";

$res_topic = mysqli_query($mysqli , $select_topic)
or die(mysqli_error($mysqli));
if(mysqli_num_rows($res_topic) < 1) {
$display_block = "<p> No Topics Exist</p>";
} else {
$display_block .=<<<END_OF_TEXT
<table>
<tr>
<th> Topic Title </th>
<th> # Of Posts </th>
</tr>
END_OF_TEXT;

while($topic_info = mysqli_fetch_array($res_topic)){
$topic_id = $topic_info[topic_id];
$topic_owner = stripslashes($topic_info[topic_owner]);
$topic_title = stripslashes($topic_info[topic_title]);
$topic_time = $topic_info[topic_time];

$post_count = "SELECT COUNT(post_id) AS post_count FROM
forum_posts WHERE topic_id='".$topic_id."' ";

$count_res = mysqli_query($mysqli , $post_count);
while($count_info = mysqli_fetch_array($count_res)){
$num_posts=$count_info[post_count];
}
$display_block .=<<<END_OF_TEXT
<tr>
<td><a href="topic.php?topic_id=$topic_id">
<strong>$topic_title</strong></a><br/>
Created on $topic_time by $topic_owner</td>
<td> $post_count posts </td>
</tr>
END_OF_TEXT;
}

mysqli_close($mysqli);
$display_block .="</table>";
}
?>
<!DOCTYPE html>
<html>
<head>
<title> Show Topics </title>
</head>
<body>
<?php echo $display_block ; ?>
<p>Would you like to <a href="topic.php">add a topic</a>?</p>
</body>
</html>

ali2k5
دوشنبه 04 شهریور 1392, 17:22 عصر
مشکل از END_OF_TEXT هست باید سرخط باشه اخرش و ...
نیاید اصلا اینجوری بنویسید باید از ob_start() و در پایان ob_get_clean() استفاده کنید
این اصلاح شده با روش خودتون هست که کار میکنه:



$select_topic = "SELECT topic_id , topic_owner , topic_title ,
DATE_FORMAT(topic_create_time , '%b %e %Y at %r') AS
topic_time FROM forum_topics
ORDER BY topic_time DESC ";

$res_topic = mysqli_query($mysqli , $select_topic)
or die(mysqli_error($mysqli));
if(mysqli_num_rows($res_topic) < 1) {
$display_block = "<p> No Topics Exist</p>";
} else {
$display_block .=<<<END_OF_TEXT
<table>
<tr>
<th> Topic Title </th>
<th> # Of Posts </th>
</tr>
END_OF_TEXT;

while($topic_info = mysqli_fetch_array($res_topic)){
$topic_id = $topic_info[topic_id];
$topic_owner = stripslashes($topic_info[topic_owner]);
$topic_title = stripslashes($topic_info[topic_title]);
$topic_time = $topic_info[topic_time];

$post_count = "SELECT COUNT(post_id) AS post_count FROM
forum_posts WHERE topic_id='".$topic_id."' ";

$count_res = mysqli_query($mysqli , $post_count);
while($count_info = mysqli_fetch_array($count_res)){
$num_posts=$count_info[post_count];
}
$display_block .=<<<END_OF_TEXT
<tr>
<td><a href="topic.php?topic_id=$topic_id">
<strong>$topic_title</strong></a>
Created on $topic_time by $topic_owner</td>
<td> $post_count posts </td>
</tr>
END_OF_TEXT;
}

mysqli_close($mysqli);
$display_block .="</table>";
}
?>
<!DOCTYPE html>
<html>
<head>
<title> Show Topics </title>
</head>
<body>
<?php echo $display_block ; ?>
<p>Would you like to <a href="topic.php">add a topic</a>?</p>
</body>
</html>

Sepax1
دوشنبه 04 شهریور 1392, 18:30 عصر
خیلی ممنون دوست عزیز .

فقط این روشی که گفتی رو می تونی یخرده بیشتر توضیح بدی