简体   繁体   English

在一个html列中显示多个sql列

[英]Displaying multiple sql columns in one html column

I have a form with multiple checkboxes which are stored as different columns in a database. 我有一个带有多个复选框的表单,这些复选框存储为数据库中的不同列。

I want to display them as a single column in a webpage, how can I do that? 我想将它们显示为网页中的单个列,我该怎么做?

HTML Form: HTML表单:

    <div class="form-group">
        <label class="col-md-2 control-label">R-11</label>
            <div class="col-md-1">
                <input type="checkbox" class="form-control" name="r11" value="R11">
            </div>
        <label class="col-md-2 control-label">E-1</label>
            <div class="col-md-1">
                <input type="checkbox" class="form-control" name="e1" value="E1">
            </div>
        <label class="col-md-2 control-label">E-2</label>
            <div class="col-md-1">
                <input type="checkbox" class="form-control" name="e2" value="E2">
            </div>
        <label class="col-md-2 control-label">E-3</label>
            <div class="col-md-1">
                <input type="checkbox" class="form-control" name="e3" value="E3">
            </div>
        <label class="col-md-2 control-label">L-1</label>
            <div class="col-md-1">
                <input type="checkbox" class="form-control" name="l1" value="L1">
            </div>
        <label class="col-md-2 control-label">R-12</label>
            <div class="col-md-1">
                <input type="checkbox" class="form-control" name="r12" value="R12">
            </div>
        <label class="col-md-2 control-label">C-1</label>
            <div class="col-md-1">
                <input type="checkbox" class="form-control" name="c1" value="C1">
            </div>
        <label class="col-md-2 control-label">C-2</label>
            <div class="col-md-1">
                <input type="checkbox" class="form-control" name="c2" value="C2">
            </div>
        <label class="col-md-2 control-label">C-3</label>
            <div class="col-md-1">
                <input type="checkbox" class="form-control" name="c3" value="C3">
            </div>
    </div>

PHP Code, generating the rows and columns: PHP代码,生成行和列:

                <?php 

    while($maininfo=mysqli_fetch_assoc($records)){

        echo "<tr>";

        echo "<td>".$maininfo['run_number']."</td>";

        echo "<td>".$maininfo['date']."</td>";

        echo "<td>".$maininfo['station']."</td>";

        echo "<td>".$maininfo['time_of_call']."</td>";

        echo "<td>".$maininfo['onscene']."</td>";

        echo "<td>".$maininfo['inservice']."</td>";

        echo "<td>".$maininfo['address']."</td>";

        echo "<td>".$maininfo['category1']."</td>";

        echo "<td>".$maininfo['category2']."</td>";

        echo "<td>".$maininfo['info']."</td>";

        echo "<td>".$maininfo['shift']."</td>";

        echo "<td>".$maininfo['name']."</td>";

        echo "<td>".$maininfo['r11']."</td>";

        echo "<td>".$maininfo['e1']."</td>";

        echo "<td>".$maininfo['e2']."</td>";

        echo "<td>".$maininfo['e3']."</td>";

        echo "<td>".$maininfo['l1']."</td>";

        echo "<td>".$maininfo['r12']."</td>";

        echo "<td>".$maininfo['c1']."</td>";

        echo "<td>".$maininfo['c2']."</td>";

        echo "<td>".$maininfo['c3']."</td>";

        echo "</tr>";

    }//end while

    ?>

I would like the table in the website to show all of the r-11 thru c-3 in one column. 我希望网站上的表格在一栏中显示所有r-11至c-3。 How can I do that? 我怎样才能做到这一点? I have tried merging a couple of them together like: 我尝试将其中的一些合并在一起,例如:

             echo "<td>".$maininfo['r11', 'e1']."</td>";

However, that doesn't work. 但是,这不起作用。

This represents the output from one database column: 这代表一个数据库列的输出:

$maininfo['r11']

This is two: 这是两个:

$maininfo['r11'] . $maininfo['e1']

Wrap those two in an HTML table cell: 将这两个包装在HTML表格单元格中:

"<td>" . $maininfo['r11'] . $maininfo['e1'] . "</td>"

Repeat as necessary for however you want to design the HTML output. 根据需要重复,但是要设计HTML输出。 Add spaces, separators, more HTML markup, etc. 添加空格,分隔符,更多HTML标记等。

Basically, the values are still individual things. 基本上,这些值仍然是个别的东西。 You simply need to concatenate the output together into the HTML structure you want. 您只需要将输出连接到所需的HTML结构中即可。 It's not up to the database to do this, or the array structure. 这不取决于数据库来执行此操作,也不取决于数组结构。 They have their own jobs to do. 他们有自己的工作要做。 It's up to you to build your output strings. 构建输出字符串由您决定。

echo "<td>".$maininfo['r11'].$maininfo['e1']."</td>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM