简体   繁体   English

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

[英]html elements in php echo aren't there when generated

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. 我在设置数据库查询结果时遇到了一些麻烦,因为出于某种原因,当我在线查看页面时,我正在回应的HTML元素被完全剥离。 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:

<?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 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. 在过去的3个小时里我一直坚持这一点(甚至没有夸大其词)试图找到我能如何回应这一点,但没有运气。 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. 我还在两个不同的托管环境中测试了这个,一个在我的机器上通过EasyPHP,另一个在我拥有的网站上。

Any help fixing this would be greatly appreciated! 任何帮助解决这个问题将不胜感激!

echo "<tr id=\"voterank\">" . $value . "</div>";

You need a TD here, and the </div> is wrong. 你需要一个TD,而</div>是错误的。

Also, you're repeating the id in each <td> in each row. 此外,您在每行的每个<td>中重复id。 IDs should be unique on the page. ID应该在页面上是唯一的。 Maybe you use class="..." here instead. 也许你在这里使用class="..."

td s require a complete table structure: td需要一个完整的表结构:

<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> . 可能是浏览器正在切断你案例中的<td>元素,因为它们在没有周围的<table>情况下是无效的。

Also, as Mike W points out , you're closing the <tr> with a </div> , while you shouldn't close anything at that point. 另外,正如Mike W指出的那样 ,你用</div>关闭了<tr> </div> ,而你不应该在那时关闭任何东西。

You should be seeing your original HTML in the real "view source" view, though. 但是,您应该在真实的“查看源”视图中看到原始HTML。

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

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. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM