dongwuchu0314 2014-09-10 04:25
浏览 14

在循环中突出显示php中的第一行

I'm getting all rows from mysql database. Now I want to highlight only first row in php while loop with class name keywordHighlight.

How do I highlight only first row in php while loop result ?

if($numSearch > 0){     

echo "<font color='green'>We found $numSearch result(s).</font>";
    echo "<table width='100%' cellpadding='0' cellspacing='0'>";
    echo "<thead>";
    echo "<tr>";                
    echo "<td class='' valign='top' width='200'></td>";
    echo "<td class='' valign='top' width='125'></td>";                             
    echo "<td class='' valign='top' width='125'></td>";
    echo "<td class='' valign='top' width='125'></td>";                             
    echo "<td class='' valign='top' width='125'></td>";                             
    echo "</tr>";   
    echo "</thead>";
    echo "<tbody>";     


while($resGetSearch =  mysql_fetch_array($getSearch)){

    $SearchCdid = $resGetSearch['cdid'];
    $SearchFamilyName =  $resGetSearch['family_name'];          
    $SearchGivenName =  $resGetSearch['given_name'];            
    $SearchCompamyCid = $resGetSearch['cid']; 
    $SearchDepartment = $resGetSearch['department'];
    $SearchTitle = $resGetSearch['title'];

    $SearchComapnyName =  mysql_query("SELECT company_name FROM company WHERE cid = '$SearchCompamyCid' ");
    $resSearchCompanyName =  mysql_fetch_array($SearchComapnyName);     
    $companyName = $resSearchCompanyName['company_name'];

    if (strlen($companyName) >= 20) {
        $companyName =  substr($companyName, 0, 10). "" . substr($companyName, -5);
    }else{
        $companyName = $companyName;
    }

    // my Highlighted class = keywordHighlight";    


    echo "<tr onclick='getDetails($SearchCdid);' >";                                        
    echo "<td valign='top' >$companyName</td>";
    echo "<td valign='top'>$SearchFamilyName</td>";
    echo "<td valign='top'>$SearchGivenName</td>";
    echo "<td valign='top'>$SearchDepartment</td>";
    echo "<td valign='top'>$SearchTitle</td>";
    echo "</td>";
    echo "</tr>";       
    }
    echo "</tbody>";
    echo "</table>";                        
    echo "<hr/>";
    echo "<br/>";   

}//elseif is not empty search
elseif($numSearch === 0){
    echo "<font color='red'>No Matches.</font>";
}
  • 写回答

6条回答 默认 最新

  • dsfgdsjfd78773 2014-09-10 04:28
    关注

    put some flag $f=0; if f==0 then do something like this:

        $highlight="<div class='keywordHighlight'>valur of first row</div>";// instead of dive you can use table also it depends on how you want to display.
    $f=$f+1;
    

    and rest in else part.

    评论

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM