简体   繁体   English

如何使用MySQL将ID的所有列值回显到行中

[英]How to echo all column values of an id into rows using mysql

I am on the way to create a webform for education related activity. 我正在为教育相关活动创建网络表单。 My mysql table looks like this 我的mysql表看起来像这样

+----+--------+---------+-----------+---------+-----------------------------
| id |schlname| trname  | pay  |oa |gross|trname2|pay2|oa2|gross2| -----etc
+----+--------+---------+-----------+---------+-----------------------------
|  1 |Greatedn|  Bredier| 1000 | 25|1025|Pastiur |1000| 25|1025  |
   2 |Meritedn|  Paskin | 1000 | 25|1025|Blazer  |1000| 25|1025  |
+----+--------+---------+-----------+---------+----------------------------

I need to take report using php query using echo statement. 我需要使用使用echo语句的php查询生成报告。 My expected report should be like this 我的预期报告应该是这样的

+----+--------+---------+-----------+-------
| id |schlname| trname  | pay  | oa |gross |
+----+--------+---------+-----------+-------
|  1 |Greatedn|  Bredier| 1000 | 25 |1025  |
                 Pastiur |1000 | 25 |1025  |
                 etc...
                 etc...
   2 |Meritedn|  Paskin | 1000 | 25 |1025  |
                 Blazer |1000  | 25 |1025  |
                 etc...
                 etc..

Your valuable ideas are expected to complete my study 您的宝贵意见有望完成我的学习

This is untested, but I'd go somewhere along these lines, maybe a double for loop if you want to make it look pretty 这未经测试,但是我会沿着这些思路走下去,如果您想使其看起来更漂亮,则可能是double for循环

        require "conn.php";
        $sql = $dbh->prepare("SELECT * FROM yourtablename WHERE 1");
        $sql->execute();
        $data_storage = $sql->fetch_all();
        for($i = 0; $i < $data_storage->rowCount(); $i++) {
            echo $data_storage[$i];
        }

Let me know if this answers your question. 让我知道这是否回答了您的问题。 Not quite sure if this is what you're asking for. 不太确定这是否是您要的。

let me know if something fails ;) 让我知道是否失败;)

<?php

$con=mysqli_connect("#","#","#","#");

if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

<div id="container">
<br><br>
<section class="column1" style="font-weight:bold;">Reference</section>
<section class="column1" style="font-weight:bold;">Language Combination</section>
<section class="column1" style="font-weight:bold;">Customer Delivery Date</section>
<section class="column1" style="font-weight:bold;">Project Status</section>
<br><br>

$result1 = mysqli_query($con,"SELECT * FROM `table` WHERE schlname="Greatedn" ");

while($row = mysqli_fetch_array($result1))
{
?> <br><br> <section class="column2"> <?php echo $row['id']; ?> </section> <?php
?> <br><br> <section class="column2"> <?php echo $row['schlname']; ?> </section> <?php
?> <br><br> <section class="column2"> <?php echo $row['trname']; ?> </section> <?php
?> <br><br> <section class="column2"> <?php echo $row['pay']; ?> </section> <?php
?> <br><br> <section class="column2"> <?php echo $row['oa']; ?> </section> <?php
?> <br><br> <section class="column2"> <?php echo $row['gross']; ?> </section> <?php
?><section class="clearboth"></section><br><br><?php
}

$result2 = mysqli_query($con,"SELECT * FROM `table` WHERE schlname="Meritedn" ");

while($row = mysqli_fetch_array($result2))
{
?> <br><br> <section class="column2"> <?php echo $row['id']; ?> </section> <?php
?> <br><br> <section class="column2"> <?php echo $row['schlname']; ?> </section> <?php
?> <br><br> <section class="column2"> <?php echo $row['trname']; ?> </section> <?php
?> <br><br> <section class="column2"> <?php echo $row['pay']; ?> </section> <?php
?> <br><br> <section class="column2"> <?php echo $row['oa']; ?> </section> <?php
?> <br><br> <section class="column2"> <?php echo $row['gross']; ?> </section> <?php
?><section class="clearboth"></section><br><br><?php
}

mysqli_close($con);

?>

</div>

CSS 的CSS

.column 1 {
float: left;
width: 15%;
overflow: hidden;
}

.container {
//Some cool stuff here
}

.clearboth {
clear: both;
}

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

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