[英]vertical column in table Display query result horizontally in html table
i want to display vertical values of the field , horizontally in html table. 我想在html表中水平显示字段的垂直值。 my table structure is like 我的表结构就像
ID Category Value (ID is Foriegn Key)
1 A 23
1 B 25
.
.
.
.
1 S 30
2 A 10
2 B 11
.
.
.
2 S 22
ID Area_A Area_B Area_C (ID is primary key)
i want to join these table and want to display query result horizontally like 我想加入这些表并想像水平显示查询结果
ID Area_A Area_B Area_C A B ........ S
1 aa bb cc 23 25 30
can anyone help me? 谁能帮我? is this possible ? 这可能吗 ?
$sql = "select * from tbl1, tbl2 where tble1.ID = tble2._ID "; $res = mysqli_query($con, $sql); while($row = mysqli_fetch_object($res)) { ?> <tr> <td><?php echo "$row->ID"; ?></td> <td><?php echo "$row->Area_A"; ?></td> <td><?php echo "$row->Area_B"; ?></td> <td><?php echo "$row->Area_C; ?></td> <td><?php echo "$row->Value "; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> <td><?php echo "$row->Value"; ?></td> </tr> <?php
but the problem is inserted data like this 但是问题是这样插入数据
this black ellipse should display horizontally and only once 此黑色椭圆应该水平显示一次
Your php code in your example creates a row in your HTML table for every row in your result set from MySQL. 您的示例中的php代码会在HTML表中为MySQL结果集中的每一行创建一行。 Change that code to create columns. 更改该代码以创建列。 php is excellent for this sort of thing; php对于这种事情非常有用。 it manipulates text and HTML tables are just text. 它操纵文本,而HTML表只是文本。
To do this you need to, actually, create two rows. 为此,您实际上需要创建两行。 One is the header row and the other the detail row. 一个是标题行,另一个是明细行。
Try something like this. 尝试这样的事情。 Please notice that this code is not debugged. 请注意,此代码未调试。
$hdr = "";
$dat = "";
while($row = mysqli_fetch_object($res)) {
$hdr = $hdr + "<td>" + $row->Category + "</td>";
$dat = $dat + "<td>" + $row->Value + "</td>";
}
echo "<tr>" + $hdr + "</tr>";
echo "<tr>" + $dat + "</tr>";
Do you see how $hdr = $hdr + table cell
accumulates a bunch of table cells for each data item, containing the Category
values in your result set? 您是否看到$hdr = $hdr + table cell
如何为每个数据项累积一堆表格单元格,并在结果集中包含Category
值? Likewise, $dat = $dat + table cell
accumulates a bunch of table cells for each data item. 同样, $dat = $dat + table cell
格会为每个数据项累积一堆表单元格。
Sorry to say I don't understand Area_A
and the other area items in your question, so I haven't tried to program those. 抱歉地说我对您的问题不了解Area_A
和其他区域项目,因此我没有尝试对它们进行编程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.