我怎么能换行

时间:2017-05-24 16:48:20

标签: php

如何每5个分数进行换行?我有以下代码,但它在一行中显示了所有结果,并且需要每5个分数开始一个新行,而不使用表格。

<?php session_start();
include ("conexion.php");    
?>

<?php

$correo=$_SESSION['s_username'];
$sql ="SELECT nombre_catalogo FROM catalogos WHERE email = '$correo'";
$res=mysqli_query($conexion,$sql);

echo "<table border='1' cellpadding='4' cellspacing='0'>";
$fecha = array();

while ($row20 = mysqli_fetch_array($res)) {

    $fecha[] = $row20['nombre_catalogo'];            

}
echo "<tr>";
echo "<td>Name</td>";
foreach($fecha as $fec) {
    echo "<td>" . $fec . "</td>";
    echo "<td>" . $fec . "</td>";

}
?>

例如,如果我的数据库中有13个分数,则会显示一行,如

*************

但它需要这样

*****
*****
***

2 个答案:

答案 0 :(得分:0)

array_chunk可以成为解决方案。

+ (NSData *)sha256DataFromData:(NSData *)data {
    unsigned char result[CC_SHA256_DIGEST_LENGTH];
    CC_SHA256([data bytes], (int)[data length], result);
    return [NSData dataWithBytes:result length:CC_SHA256_DIGEST_LENGTH];
}

答案 1 :(得分:0)

您正在寻找str_split() PHP DOC

请参阅我的示例:

<?php
    $string = "0123456789ABCDEF";
    // split the string every 5 chars, return as array
    $result = str_split($string, 5);
    // now create new string by imploding, with linebreak as glue
    $result1 = implode(PHP_EOL, $result);
    // OR
    $result2 = implode("\r\n", $result);

    print_r($result1);
    print_r($result2);
?>