我有一个与php和html相关的问题。 我试图从mysql数据库写一个表。
我的问题是:为什么它在写表之前写了“SEMIFINAL 2”文本,但在代码中,表是在文本“SEMIFINAL 2”之前写的?
我真的可以使用一些帮助。非常感谢。
P.S。这是代码
<html>
<style>
table {
color: #333;
font-family: Helvetica, Arial, sans-serif;
width: 640px;
border-collapse:
collapse; border-spacing: 0;
}
td, th {
border: 1px solid transparent; /* No more visible border */
height: 30px;
transition: all 0.3s; /* Simple transition for hover effect */
}
th {
background: #DFDFDF; /* Darken header a bit */
font-weight: bold;
text-align: center;
}
td {
background: #FAFAFA;
text-align: center;
}
/* Cells in even rows (2,4,6...) are one color */
tr:nth-child(even) td { background: #F1F1F1; }
/* Cells in odd rows (1,3,5...) are another (excludes header cells) */
tr:nth-child(odd) td { background: #FEFEFE; }
tr td:hover { background: #666; color: #FFF; } /* Hover cell effect! */
</style>
<?php
$host="localhost";
$username="root";
$password="";
$db_name="lol";
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("lol") or die("Cannot connect to database");
$query="call semi2";
$results = mysql_query($query);
print('<table align=center>');
print ("<tr>");
echo '<th>First Name</th>';
echo '<th>Last Name</th>';
echo '<th>Victories</th>';
echo "</center>";
$nr_val=0;
if($results === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($row=mysql_fetch_row($results)){
echo" <tr>\n";
foreach($row as $value){
echo "<td>$value</td>";
$nr_val++;
}
echo"</tr>";
}
$coln=mysql_num_fields($results);
$nr_inreg=$nr_val/$coln;
echo "<br>";
echo "<center>";
if ($nr_inreg>0)
echo "SEMIFINAL 2";
else
die ("Can't find any recording....");
echo "</center>";
mysql_close();
?>
</html>
答案 0 :(得分:1)
在输出文本
之前添加闭包表标签