gpt4 book ai didi

php - 如何让MySQL数据分两列显示?

转载 作者:行者123 更新时间:2023-11-29 14:46:34 24 4
gpt4 key购买 nike

我想让数据显示在 2 列而不是一列中,这是我当前用于在 1 列中显示数据的代码:

    <?php 
include("config.php");
include("opendb.php");
$get_cats = mysql_query("SELECT * FROM `categories` ORDER BY `displayorder`") or die(mysql_error());
$get_info = mysql_query("SELECT * FROM `systeminfo`") or die(mysql_error());
$info = mysql_fetch_array($get_info);
while($cats = mysql_fetch_array($get_cats)) {
$get_rares = mysql_query("SELECT * FROM `rares` WHERE `catid`='".$cats['id']."'") or die(mysql_error());
echo("<h2>".$cats['name']."</h2><br>
<table width=\"100%\" border=\"0\">
<tr>
<td width=\"20%\" style=\"text-align:center\"><b>Image</b></td>
<td width=\"40%\" style=\"text-align:left\"><b>Item Name</b></td>
<td width=\"10%\" style=\"text-align:center\"><b>Value</b></td>
<td width=\"30%\" style=\"text-align:center\"><b>Last Updated</b></td>
</tr>
");
$color1 = $info[stripe1];
$color2 = $info[stripe2];
$row_count = 0;
while($rare = mysql_fetch_array($get_rares)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<tr>
<td width="5%" style="text-align:center;background-color:#<?php echo $row_color; ?>"><img alt="" src="<?php echo("".$info[imagepath]."".$rare['image'].""); ?>"></td>
<td width="20%" style="text-align:left;background-color:#<?php echo $row_color; ?>"><?php echo $rare['name']; ?></td>
<td width="20%" style="text-align:center;background-color:#<?php echo $row_color; ?>"><?php echo $rare['value']; ?> Credits</td>
<td width="10%" style="text-align:center;background-color:#<?php echo $row_color; ?>"><?php echo $rare['lastedited']; ?></td>
</tr>
<?php
$row_count++;
}
echo("</table><br>

");
}
?>

当前显示为:

1
_________

2
_________

3
_________

4
_________

5
_________

6
_________

我希望它显示如下:

1         | 2
_________ | _________
3 | 4
_________ | _________
5 | 6
_________ | _________

最佳答案

这确实和 MySQL 没有任何关系。 MySQL 只是数据的来源。你想要这样的东西:

$record = 0;
while($rare = mysql_fetch_array($get_rares)) {
if ($record % 2 == 0) {
echo "<tr>"; // if on an 'even' record, start a new row
}
echo "<td>{$rare['something']}</td>";
$record++;
if ($record % 2 == 0) {
echo "</tr>"; // close the row if we're on an even record
}
}

关于php - 如何让MySQL数据分两列显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6861885/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com