[英]In my table, colour is appearing only on the even rows
当我尝试从数据库获取数据时,我想更改偶数和奇数行的颜色。 但是表上仅出现偶数行的颜色。 我为偶数和奇数行定义了不同的颜色。 但是奇数行的颜色没有出现。 我的代码如下所示。
任何建议将不胜感激
<head><style type="text/css">
.colr tr:nth-child(odd){
background-color: #4286f4; }
.colr tr:nth-child(even){
background-color: #92f441;}
</style>
</head>
<body>
<body>
<?php
$con=@mysql_connect("localhost","root","")or die(mysql_error());
$db=@mysql_select_db("portal",$con) or die(mysql_error());
echo "<div class='table-users'>
<div class='header'>Applicants</div>
<table cellspacing='0'>
<tr>
<th >ID </th>
<th>Application for</th>
<th>Name</th>
<th>Date Of Birth</th>
<th>Qualification</th>
<th>Passing Year</th>
</tr> </table>
</div>";
$sql='SELECT * FROM tbl_applicantinfo ';
$sql1=mysql_query('Select * FROM tbl_academic');
$retval = mysql_query( $sql, $con );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
$selected=$_GET['aap_position'];
if($_GET['aap_position']=="all"){
$sql=mysql_query('SELECT * FROM tbl_applicantinfo;
echo "<div class='table-users'>
";
while ($row=mysql_fetch_array($sql)){
echo "<div >
<table cellspacing='0' class='colr'>
<tr>
<td >{$row['SrNo']}</td>
<td>{$row['position']}</td>
<td>{$row['applicantname']}</td>
<td>{$row['date_birtth']}</td>
<td>{$row['degree']}</td>
<td>{$row['year_passing']}</td>
</tr> </table></div>";
}}
mysql_close($con);
?> </body>
尝试以下操作:(在while
循环之前启动表,只有<tr>
会进入while循环,如果将table
放入while
循环中,则每次生成新table
,将仅应用一个css(用于ODD或EVEN tr
) )
<head><style type="text/css">
.colr tr:nth-child(odd){
background-color: #4286f4; }
.colr tr:nth-child(even){
background-color: #92f441;}
</style>
</head>
<body>
<body>
<?php
$con=@mysql_connect("localhost","root","")or die(mysql_error());
$db=@mysql_select_db("portal",$con) or die(mysql_error());
echo "<div class='table-users'>
<div class='header'>Applicants</div>
<table cellspacing='0'>
<tr>
<th >ID </th>
<th>Application for</th>
<th>Name</th>
<th>Date Of Birth</th>
<th>Qualification</th>
<th>Passing Year</th>
</tr> </table>
</div>";
$sql='SELECT * FROM tbl_applicantinfo ';
$sql1=mysql_query('Select * FROM tbl_academic');
$retval = mysql_query( $sql, $con );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
$selected=$_GET['aap_position'];
if($_GET['aap_position']=="all"){
$sql=mysql_query('SELECT * FROM tbl_applicantinfo;
echo "<div class='table-users'>
<div ><table cellspacing='0' class='colr'>";
while ($row=mysql_fetch_array($sql)){
echo "<tr>
<td >{$row['SrNo']}</td>
<td>{$row['position']}</td>
<td>{$row['applicantname']}</td>
<td>{$row['date_birtth']}</td>
<td>{$row['degree']}</td>
<td>{$row['year_passing']}</td>
</tr> ";
} echo "</table></div>"; }
mysql_close($con);
?> </body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.