【问题标题】:How to put a dashed line around a specific row in php and mysql如何在php和mysql中的特定行周围放置虚线
【发布时间】:2013-12-05 22:47:31
【问题描述】:

我刚刚从 PHPmyadmin 中找到了如何显示我的表格,但我希望第五行有一个虚线轮廓。我知道如何在 CSS“border-style:dashed;”中制作虚线边框。问题是我的代码如何从数据库中调用我的数据并将其放入 HTML 表中,我是否需要重新编码以使第五行变为虚线?

// Get all the data from the "epl" table
$result = mysql_query("SELECT * FROM epl") 
or die(mysql_error());  

echo "<table border='1'>";
echo "<tr> <th>Pos</th> <th>Team</th> <th>PLD</th> <th>W</th> <th>D</th> 
<th>L</th> <th>F</th> <th>A</th> <th>GD</th> <th>PTS</th> </tr>";

 // keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row['Pos'];
echo "</td><td>"; 
echo $row['Team'];
echo "</td><td>"; 
echo $row['PLD'];
echo "</td><td>"; 
echo $row['W'];
echo "</td><td>";
echo $row['D'];
echo "</td><td>";
echo $row['L'];
echo "</td><td>";
echo $row['F'];
echo "</td><td>";
echo $row['A'];
echo "</td><td>";
echo $row['GD'];
echo "</td><td>";
echo $row['PTS'];
echo "</td></tr>"; 
} 

我正在尝试做的一个例子是'http://www.bbc.co.uk/sport/football/tables'

【问题讨论】:

    标签: php mysql regex html css


    【解决方案1】:
    $count = 1;
    while($row = mysql_fetch_array( $result )) {
       if($count == 5) {
         echo "<tr style='border-style:dashed'><td>"; 
       }
       else {
         echo "<tr><td>"; 
       }
       //other table stuff
    
       $count++;
    }
    

    不是很优雅,但它应该可以工作。

    【讨论】:

    • 我以为这会奏效,但它似乎没有阅读声明
    • 这有助于选择行,但不会在行周围形成虚线。不允许直接样式化。您应该将边框放在元素上,并使用border-right 和border-left 删除列之间的边框。
    【解决方案2】:

    也许

    $count = 1;
    while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table
    if($count === 5){
    echo "<tr class=\"dashed\"><td>"; 
    } else {
    echo "<tr><td>"; 
    }
    //All others <td>
    $count++;
    }
    

    然后创建一个 CSS 类

    .dashed { border-bottom: 1px dashed white; }
    

    【讨论】:

    • 你把类名中的双引号弄乱了,要么需要转义,要么改成单引号。
    • 感谢@Novocaine88:P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    • 2013-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多