Jump to content

CSS & HTML In PHP Echo Statement


jamesjmann

Recommended Posts

Hey, I posted a thread before about a news cms I've been developing. And right now I'm trying to flesh out the css of the articles I post on the home page. Now the problem I having is everytime I place a <span class=""></span> or <p class=""></p> or even <div class=""></div>, my web page does NOT load, and instead gives me an error.

 

Parse error: syntax error, unexpected T_STRING in /home/content/d/j/s/djsmiley/html/index.php on line 405

 

Now, I know it's possible to add css to a PHP echo statement, but I'm clearly doing something wrong.

 

Here's the code for the php echo statement with the css included:

 

<? 
include("dbconnect.php"); //include the file to connect to the database 
$getnews = mysql_query("SELECT * FROM mynews ORDER BY id DESC"); //query the database for all of the news 

while($r=mysql_fetch_array($getnews)){ //while there are rows in the table 
extract($r); //remove the $r so its just $variable 

echo("<br><span class="NewsID">$type</span> <span class=h2>$title</span><br><br>
<em>posted by <strong>$user</strong> | added on $time</em><br><br> 
$message<br><br>
<label class="fltlft2"><img src="../../Websites/DJSmiley.Net/images/Icons/Arrows/Right.png" width="20" height="20"/></label><a href=$url>Read more - $url</a>
		<div class="newsLikeShareRate">
				  <table width="100%" border="0">
					<tr>
					  <td width="3%" height="21"><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
						  <fb:like href="$url" show_faces="true" width="450" font="arial"></fb:like>
                              </td>
					<td width="65%"><a name="fb_share" id="fb_share4" type="icon_link" 
		   share_url="$url">Share</a>
						  <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" 
				type="text/javascript"></script></td>
					  <td width="32%">Rate this article:
					   </td>
					</tr>
				  </table>
		</div>"); 

} 

?>

 

If you're wondering why there's a facebook script in there, I made it to where everytime a new post is added, a facebook like and share button are added, and are assigned the url I specify when the article is posted.

 

Well, I think that's it for the code. Can anyone tell me what I'm doing wrong?

Link to comment
Share on other sites

You have surrounded your string with double quotes and have double quotes in the HTML. As soon as PHP sees the second double quote, that terminates the string and you get an error. Just surround your string with single quotes. Also you don't need to put parenthesis around the string when using echo.

 

Ken

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.