0

我尝试从表格中打印出所有用户电子邮件,但我希望奇数打印为红色,偶数打印为蓝色。如何在while循环中做到这一点?

$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++;
    }
4

1 回答 1

4
$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++;
    }
于 2012-12-15T03:27:47.687 回答