dptiq46022 2012-12-15 03:23
浏览 48
已采纳

php在行中打印不同的颜色

I try to print out all user email from table, but i want odd number print in red even number print in blue. how to do this in while loop?

$connect=mysql_connect("localhost", "root", "");
$database=mysql_select_db("phplogin", $connect);

$SQL=mysql_query("SELECT * FROM users");
$num=mysql_num_rows($SQL);
$start=0;

while($start<$num){
    $result_id=mysql_result($SQL, $start, "id");
    $result_email=mysql_result($SQL, $start, "email");

    echo "<b style='color:red'>" . $result_id . $result_email . "</b><br/>";
    echo "<b style='color:blue'>" . $result_id . $result_email . "</b><br/>";

    $start++;
    }
  • 写回答

1条回答 默认 最新

  • duanjiangzhi6851 2012-12-15 03:27
    关注
    $connect=mysql_connect("localhost", "root", "");
    $database=mysql_select_db("phplogin", $connect);
    
    $SQL=mysql_query("SELECT * FROM users");
    $num=mysql_num_rows($SQL);
    $start=0;
    
    while($start<$num){
        $result_id=mysql_result($SQL, $start, "id");
        $result_email=mysql_result($SQL, $start, "email");
        if ($start&1) {
          echo "<b style='color:red'>" . $result_id . $result_email . "</b><br/>";
        }
        else {
          echo "<b style='color:blue'>" . $result_id . $result_email . "</b><br/>";
        }
        $start++;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致