如何使用mysql将id的所有列值回显到行中

时间:2015-07-08 15:07:04

标签: php mysql

我正在为教育相关活动创建一个网络表单。我的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  |
+----+--------+---------+-----------+---------+----------------------------

我需要使用echo语句使用php查询进行报告。我的预期报告应该是这样的

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

您的宝贵意见有望完成我的研究

2 个答案:

答案 0 :(得分:0)

这是未经测试的,但我会沿着这些线去某个地方,如果你想让它看起来很漂亮,可能是一个双循环

        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];
        }

如果这回答了您的问题,请告诉我。不太确定这是否是你所要求的。

答案 1 :(得分:0)

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

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

.container {
//Some cool stuff here
}

.clearboth {
clear: both;
}