简体   繁体   中英

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:

    <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 

    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. 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:

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

Repeat as necessary for however you want to design the HTML output. Add spaces, separators, more HTML markup, etc.

Basically, the values are still individual things. You simply need to concatenate the output together into the HTML structure you want. 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>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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