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.

<?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> 

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

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; ?>

ok, I got it to work, thanks for your help guys, I will look up proper syntaxs, im like a week into PHP so I need to read alot of material at this point., im going to try and add div class to the other $rows, hopefully I dont ruin the internet lol.

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.

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> ";
?>

 

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.