dongningwen1146 2013-06-16 07:23
浏览 55
已采纳

生成时,php echo中的html元素不存在

I'm having a bit of trouble styling my database query results because, for some reason, the HTML elements I'm echoing are being stripped out completely when I view the page online. The tags ( and , etc) aren't commented, just completely gone when viewing the source of the page.

The idea of this script is for it to get the voting results of players. Using the current script, the data all shows up, so there isn't a connection issue. Here's the php I've got currently:

<?php

$user_name = "TAKEN OUT";
$password = "TAKEN OUT";
$database = "TAKEN OUT";
$server = "TAKEN OUT";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

$SQL = "SELECT * FROM votesql ORDER BY votes DESC";
$result = mysql_query($SQL);
$value = 1;
while ($db_field = mysql_fetch_assoc($result)) {
echo "<tr id=\"voterank\">" . $value . "</div>";
echo "<td id=\"vote-place\">" . $value . "</td>";
echo "<td id=\"vote-playername\">" . $db_field['playername'] . "</td>";
echo "<td id=\"vote-count\">" . $db_field['votes'] . "</td>";

$value = $value + 1;

echo ("</tr>");
}

mysql_close($db_handle);

}
else {
print ("Database NOT Found ");
mysql_close($db_handle);
}

?>

This results in a page displaying information very similar to this:

11Playerone1222Playertwo11261

When I view the source of the page, it is shown as a simple block of text with no elements. I've been stuck on this for the past 3 hours (not even exaggerating) trying to find how I can echo this out, but with no luck. I've also tested this on two different hosting environments, one on my machine via EasyPHP, and the other via a site that I own.

Any help fixing this would be greatly appreciated!

  • 写回答

4条回答 默认 最新

  • douhao123457 2013-06-16 07:30
    关注

    tds require a complete table structure:

    <table>
     <tr>
      <td>Column 1 </td>
      <td>Column 2 </td>
     <tr>
    </table>
    

    it could be that the browser is cutting out the <td> elements in your case because they're invalid without a surrounding<table>.

    Also, as Mike W points out, you're closing the <tr> with a </div>, while you shouldn't close anything at that point.

    You should be seeing your original HTML in the real "view source" view, though.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?