douji5746 2019-04-14 18:53
浏览 142

如何动态创建n个列?

I would like to embellish my code a little .. this page serves as a summary to visualize the data present in my database, I would like to do so that it does not just look at one button per column but I would like to make sure to put 5 buttons for column according to a precise graphic order .. the solution that seems to me more appropriate is the use of .. I implemented everything and the buttons are created dynamically in the right way .. the only thing is that I print every time on a new line a button ... does anyone know how to be able to put 5/4 buttons on a line and tell them to wrap automatically? I attach the photo of my result ..

<!DOCTYPE html>
<?php 
    session_start();
    if(!isset($_SESSION["username"])){
        header('location: ../../../index.php');
    }else
    {

?>
<?php
$servername = "localhost";
$username = "root";
$password = "Salc!2018";
$dbname = "my_progettocantiere";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT idCantiere,nomeCantiere,codiceCommessa,indirizzoCantiere FROM Cantiere";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    echo'<br><br><br>';
    int $cont = 0;
        echo '<table align="center" border="0px" width = "1300px">';
        echo '<tr align="center">';
        while($row = $result->fetch_assoc()) 
        {
        if($cont == 5)
        {
        echo '<td><a class="myButton" href="sceltaOperazione.php?idCantiere=' . $row["idCantiere"] . '">' . $row["nomeCantiere"] . '</a></td>';
        }
        else
        {
        echo '<tr><td><a class="myButton" href="sceltaOperazione.php?idCantiere=' . $row["idCantiere"] . '">' . $row["nomeCantiere"] . '</a></td></tr>';

        }

$cont++;
echo'</tr>';
        echo '</table>';


    echo'<br><br><br>';
        echo '<table align="center" border="1px" width = "1300px">';
        echo '<tr><td align="center" bgcolor="000035">';
        echo '<a href="../../pagineHtml/inserimento/inserimentoGenerale/inserimentoCantiere.php" class="myButton" alt="Nuovo Cantiere +">Nuovo Cantiere +</a>';
        echo '</tr></td>';
        echo '</table>';

} else {
    echo "0 results";
}
//$idCantiere = $_POST["idCantiere"];



$conn->close();
?>

<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
   <title>Progetto Cantiere</title>
    <!-- Bootstrap -->
    <link href="../paginaIniziale/css/bootstrap-4.0.0.css" rel="stylesheet">
  </head>
    <style>

    .myButton {
    -moz-box-shadow:inset 0px 1px 0px 0px #000035;
    -webkit-box-shadow:inset 0px 1px 0px 0px #000035;
    box-shadow:inset 0px 1px 0px 0px #000035;
    background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #000035), color-stop(1, #000035));
    background:-moz-linear-gradient(top, #000035 5%, #000035 100%);
    background:-webkit-linear-gradient(top, #000035 5%, #000035 100%);
    background:-o-linear-gradient(top, #000035 5%, #000035 100%);
    background:-ms-linear-gradient(top, #000035 5%, #000035 100%);
    background:linear-gradient(to bottom, #000035 5%, #000035 100%);
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#000035', endColorstr='#000035',GradientType=0);
    background-color:#ffffff;
    -moz-border-radius:6px;
    -webkit-border-radius:6px;
    border-radius:6px;
    border:1px solid #000035;
    border:1px solid #000035;
    display:inline-block;
    cursor:pointer;
    color:#ffffff;
    font-family:Arial;
    font-size:28px;
    font-weight:bold;
    padding:32px 76px;
    text-decoration:none;
    text-shadow:0px 1px 0px #1570cd;
}
.myButton:hover {
    background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #000035), color-stop(1, #000035));
    background:-moz-linear-gradient(top, #000035 5%, #000035 100%);
    background:-webkit-linear-gradient(top, #000035 5%, #000035 100%);
    background:-o-linear-gradient(top, #000035 5%, #000035 100%);
    background:-ms-linear-gradient(top, #000035 5%, #000035 100%);
    background:linear-gradient(to bottom, #000035 5%, #000035 100%);
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#000035', endColorstr='#000035',GradientType=0);
    background-color:#000035;
}
.myButton:active {
    position:relative;
    top:1px;
}

    </style>

  <body>
<table align="center">
  <tr >
  <br><br><br><br><br><br><br><br><br>
                </td>
                <td style=" border-style: none" colspan="19"> <img src="../../../login/images/logo.jpg"  width="300px"  height="100px" alt="Logo SALC.SPA"></td>
            </tr>
            </table>
  </body>
</html>
<?php } ?>



I am attaching photo of my results ..

Screen

  • 写回答

2条回答 默认 最新

  • duanleiming2014 2019-04-14 19:08
    关注

    You can use a css grid or flexbox, put your buttons inside a div and style it:

    div {
      display: flex;
    }
    

    You can also look at this guide to understand how it works and learn some useful attributes to customize it better: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器