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

生成时,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.

    打赏 评论
  • donglv5269 2013-06-16 07:30
    echo "<tr id=\"voterank\">" . $value . "</div>";
    

    You need a TD here, and the </div> is wrong.

    Also, you're repeating the id in each <td> in each row. IDs should be unique on the page. Maybe you use class="..." here instead.

    打赏 评论
  • dongyixiu3110 2013-06-16 07:35

    change this:

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

    to:

    echo "<tr>";
    echo "<td id=\"voterank\">" . $value . "</td>";
    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>";
    echo "</tr>";
    
    打赏 评论
  • doushan1946 2013-06-16 09:16

    A little simple:

    echo '<tr>
    <td id="voterank">'.$value'.</td>
    <td id="vote-place">'.$value.'</td>
    <td id="vote-playername">'.$db_field['playername'].'</td>;
    <td id="vote-count">'.$db_field['votes'].'</td>
    </tr>';
    

    If you begin echo with single quotes, you won't need use (/) before double quotes. Good luck.

    打赏 评论

相关推荐 更多相似问题