The Little Guy Posted March 24, 2009 Share Posted March 24, 2009 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] Quote Link to comment https://forums.phpfreaks.com/topic/150836-bad-display-when-script-tag-gets-added/ Share on other sites More sharing options...
fry2010 Posted March 24, 2009 Share Posted March 24, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/150836-bad-display-when-script-tag-gets-added/#findComment-792704 Share on other sites More sharing options...
The Little Guy Posted March 24, 2009 Author Share Posted March 24, 2009 I think the problem was because I was placing a display type of table-cell on the div. When I replace that with a left float, it displays fine. I wonder why... Quote Link to comment https://forums.phpfreaks.com/topic/150836-bad-display-when-script-tag-gets-added/#findComment-792933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.