Jump to content

Keep getting errors when tryng to apply CSS


renegade44

Recommended Posts

Parse error: syntax error, unexpected '<', and I also get one with a ',' or ';'.

 

 

here is my code:if ($result) {

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

$url = 'comments.php?id='.$row['id'];

echo <div class='title_class'>.$row['title'].</div>;

'.$row['sd'].'<br />

Posted by : <b>'.$row['author'].'</b><br />

'.$row['post'].'<br />

<a href="javascript:openComments(\''.$url.'\')">Add new comment or view posted comments</a></p>';

}

} else {

echo 'There are no news posts to display';

}

?>

</body>

</html> 

 

 

the line with the error is: echo <div class='title_class'>.$row['title'].</div>;

 

If I take out the div class, it works normal, so Ive gotten as far as to dtermine that I am not properly doing the div class correctly.

 

I am basically trying to add CSS to the news posts in the news management system I have in place, I cant seem to get around this no mater what I try so I would be extremely thankful if someone here manages to help me fix this.

Link to comment
Share on other sites

<?php
if ($result) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
	?>
		<div class="title_class">
			<?php echo $row['title'] ?>
		</div>
		<?php echo $row['sd'] ?>
		<br />
		Posted by : <strong><?php echo $row['author'] ?></strong>
		<br />
		<?php echo $row['post'] ?>
		<br />
		<a href="javascript:openComments('comments.php?id=<?php echo $row['id'] ?>')">Add new comment or view posted comments</a>
	<?php
}
} else {
echo 'There are no news posts to display';
}
?>
</body>
</html> 

Link to comment
Share on other sites

Look up PHP Proper Syntax please. These are really basic errors you should be able to solve yourself.

 

<?php
if ($result) {
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $url = 'comments.php?id='.$row['id'];
        echo "<div class='title_class'>" . $row['title'] . "</div> " . $row['sd'] . "<br />
               Posted by : <b>" . $row['author'] . "</b><br />
               " . $row['post'] . "<br />
              <a href=\"javascript:openComments('" . $url . "')\">Add new comment or view posted comments</a></p>";
    }
} else {
    echo 'There are no news posts to display';
}
?>
</body>
</html>  

 

How you were going in and out the echo statement and mixing and matching all different types of " and ' was causing the error. Above should be formatted properly

Link to comment
Share on other sites

Just fyi, in alternate syntax (which is better for displaying html):

 

<?php if ($result): ?>
<?php while ($row = mysql_fetch_assoc($result)): ?>
	<div class="title_class"><?php echo $row['title'] ?></div>
	<?php echo $row['sd'] ?><br />
	Posted by : <strong><?php echo $row['author'] ?></strong><br />
	<?php echo $row['post'] ?><br />
	<a href="javascript:openComments('comments.php?id=<?php echo $row['id'] ?>')">Add new comment or view posted comments</a>
<?php endwhile; ?>
<?php else: ?>
There are no news posts to display
<?php endif; ?>

Link to comment
Share on other sites

ok, I added the divs to each element and I have it where I get no errors. here is my code

if ($result) {

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

        $url = 'comments.php?id='.$row['id'];

        echo "<div class='title_class'>" . $row['title'] . "</div> ";

"<div class='date_class'>" . $row['sd'] . "</div> ";

"<div class='post_class'>" . $row['post'] . "</div> "; "

<a href=\"javascript:openComments('" . $url . "')\">Add new comment or view posted comments</a></p>";

    }

} else {

    echo 'There are no news posts to display';

}

?>

</body>

</html> 

 

 

the weird thing is that just the "title" field is showing up on the website, the other fields are not there.

 

im sorry for coming off like a noob lol, i guess I am, I basically replicated what you did for the first tag, and did the same for the other tags, hopefully its something minor I can fix.

Link to comment
Share on other sites

This code is invalid:

 

<php
echo "<div class='title_class'>" . $row['title'] .   "</div> ";
      "<div class='date_class'>" . $row['sd'] . "</div> ";
?>

 

You need to either echo each line, or concatenate them with the '.' operator, like so:

 

<?php
echo "<div class='title_class'>" . $row['title'] .   "</div> ";
echo "<div class='date_class'>" . $row['sd'] . "</div> ";
?>

 

or

 

<?php
echo "<div class='title_class'>" . $row['title'] .   "</div> " . 
    "<div class='date_class'>" . $row['sd'] . "</div> ";
?>

 

Link to comment
Share on other sites

hey guys, I was able to get everything working except one thing, I would like to be able to edit the "post comments" font, I am ssuming the issue I have is the ahref:javascript,etc thats in the middle, do you guys have any idea how to set it up so I can apply CSS to the last line?

Link to comment
Share on other sites

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.