Jump to content

Bad Display when script tag gets added


The Little Guy

Recommended Posts

When I use this code on my page, it displays perfectly fine.

<?php
echo '
<div class="content">';
	$sql = mysql_query("SELECT * FROM feed WHERE owner = '$_id' ORDER BY `date` DESC LIMIT 1")or die(mysql_error());
	if(mysql_num_rows($sql) == 1){
		$row = mysql_fetch_array($sql);
		$status = htmlentities($row['status']);
	}else{
		$status = 'What\'s going on?';
	}
	echo '<div class="fontbig" id="status">
	<a href="javascript:void(0);" onclick="setStatus(parentNode.id,\''.$_first.'\');">'.$_first.' '.$status.'</a>
	</div>
</div>
?>

 

When I add a script tag like the following, it gets all messed up, and doesn't display correctly...

 

<?php
echo '
<div class="content">';
	$sql = mysql_query("SELECT * FROM feed WHERE owner = '$_id' ORDER BY `date` DESC LIMIT 1")or die(mysql_error());
	if(mysql_num_rows($sql) == 1){
		$row = mysql_fetch_array($sql);
		$status = htmlentities($row['status']);
	}else{
		$status = 'What\'s going on?';
	}
	echo '<div class="fontbig" id="status">
	<a href="javascript:void(0);" onclick="setStatus(parentNode.id,\''.$_first.'\');">'.$_first.' '.$status.'</a>
	</div>
</div><script type="text/javascript">myStatus=\''.$status.'\';</script>';
?>

 

I have ran my code through the w3 HTML validator, and it validates as valid HTML, so why does it do this?

 

The following attachment shows the problem, the left image is how it should look, and the one on the right is what happens after placing the script tag.

 

[attachment deleted by admin]

Link to comment
Share on other sites

that seems very odd. Your first script seems to be treating the html as php code at the bottem yet it displays correctly. The second is treating it correctly as html yet doesnt display correctly...

 

Where you have this on your second script:

(parentNode.id,\''.$_first.'\');">'.$_first.' '.$status.'</a>

 

try replacing it with this:

(parentNode.id,\''.$_first.'\');">'.$_first.' '.$status.</a>

As that seems to be how the top code is working...

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.