Jump to content

Recommended Posts

I am just trying to make a simple news script. I am trying to display all the news posts and their comments underneath them. Any ideas why I am getting:

Parse error: syntax error, unexpected $end in /Applications/MAMP/htdocs/jstar/test.php on line 69

 

Heres my code:

<?php
require("constants.php");

$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
query_check($connection);


$db_select = mysql_select_db(DB_NAME, $connection);
query_check($db_select);
?>
<?php
function query_check($check) {
if(!$check) {
	die ("OOOPS: " . mysql_error());
}
}

function get_news() {
global $connection;
$query = ("SELECT * FROM news ORDER BY id ASC");
query_check($query);
$news = mysql_query($query, $connection);
return $news;
}

function get_comments($id) {
global $connection;
$query = ("SELECT * FROM comments WHERE newsid = {$id} ORDER BY id ASC");
query_check($query);
$comments = mysql_query($query, $connection);
return $comments;
}

//This will enable 
function get_news_id($news_id) {
global $connection;
$query = ("SELECT * FROM news WHERE id={$news_id} LIMIT 1");
$query = mysql_query($query, $connection);
query_check($query);
if($id = mysql_fetch_array($query)) {
	return $id;
} else {
	return NULL;
}
}
?>
<?php

$get_news = get_news();

while ($news = mysql_fetch_array($get_news)) {
	echo "{$news['title']}<br />";

	$get_comments = get_comments($news['id']);

	while ($comments = mysql_fetch_array($get_comments)) {
		echo "{$comments['comment]}<br />";
	}
}

?>
<?php
if(isset($connection)) {
mysql_close($connection);	
}
?>

Link to comment
https://forums.phpfreaks.com/topic/169712-solved-stuck-at-an-unexpected-end/
Share on other sites

There is no problems with that script. Your code works fine.

 

However I do not see the point in doing

<?php

// some php code here
?>
<?php

// some more php code here

?>

 

If you're not going to put anything between the code blocks then there is no need to go out of php and then immediately back in to php.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.