2017-11-21 6 views
0

データベースからデータを取得しようとすると、偶数行と奇数行の色を変更します。しかし、偶数行の色だけがテーブルに表示されます。私は、偶数行と奇数行で異なる色を定義しました。しかし、奇妙な行の色が表示されません。私のコードは以下の通りです。私のテーブルでは、色は偶数行にのみ表示されます

任意の提案は

<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 
    [email protected]_connect("localhost","root","")or die(mysql_error()); 
    [email protected]_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> 
+0

これは実際のコードの無効 – nogad

+0

私が持っているSHことカント)が適用されますpost.Realの問題はCSSであり、他のすべてのものはうまく動作しています –

+0

@HassanRana Try https://stackoverflow.com/questions/47405708/in-my-table-only-even-rows-color-appear- 47405838#47405838 –

答えて

0

を理解されるであろう、この方法を試してください(あなたが、あなたのwhileループ内で新しいtableを生成するたびにtableを入れた場合のみ<tr>は、whileループでなり、whileループの前にテーブルを開始、そして唯一の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 
    [email protected]_connect("localhost","root","")or die(mysql_error()); 
    [email protected]_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> 
+0

それは動作しませんでした。 –

+0

'class = 'table-users''、 'class = 'colr''はOKです –

+0

ループの前にテーブル属性を試してみましたが動作しませんでした –

関連する問題