0

一个页面使用 PHP GNU Multiple Precision (GMP) 来确定每列应该有多少行。虽然代码有效,但我们希望将应用程序迁移到不支持PHP5-GMP模块的新主机。也就是说,生成和填充可能并不总是具有偶数个结果的两列表的最佳替代方法是什么?此外,桌子设计可能不是最好的,所以我对替代品持开放态度。

下面从这里获取的代码让我们很接近,但由于它使用mysql_fetch_array,它放置的项目如下:

a   b
c   d

代替

a   c
b   d

有没有办法让它在第一个例子中显示?

较新的代码:

<head>
<style>
.container { width: 400px; float: left; }
.container .item { width: 50%; float: left; height: someFixedHeight; }
</style>
</head>
<?php
mysql_select_db("database",$db);
$cat= $_GET["cat"];
echo '<div class="container">';
$q = mysql_query("SELECT * FROM name WHERE Field4 = '$cat'",$db);
while ($res = mysql_fetch_array($q)){
    echo '<div class="item">' . $res['Field1'] . '</div>';
}
echo '</div>';
?>

原始代码:

<div id="bit-list" align="center" >
<table class="list" width="600" border="0" align="center">
<tr>

<td width="300" height="72" valign="top" border="1">
<div align="left">
<?php
$result = mysql_query("SELECT * FROM name WHERE field4 = '$cat' ",$db);
$myrow3 = mysql_fetch_row($result);
$num_rows = mysql_num_rows($result);
$d3 = gmp_div_q("$num_rows", "2", GMP_ROUND_PLUSINF);
$i = 1;
$result8 = mysql_query("SELECT * FROM name WHERE field4 = '$cat' ",$db);
while ($myrow3 = mysql_fetch_row($result8))
    {
    if ($i <= gmp_strval($d3))
    {
        echo "<p>";
        echo '<a href="detail.php?';
        echo 'page=';
        echo "$myrow3[2]";
        echo '&';
        echo 'pnum=';
        echo "$myrow3[6]";
        echo '">';
        echo "$myrow3[1]";
        echo "</p>";
        $i = $i + 1;
    }
        else
    {
    }
    }
?>
</div></td>

<td width="300" valign="top" border="1">
<div align="left">
<?php
$result = mysql_query("SELECT * FROM name WHERE field4 = '$cat' ",$db);
$myrow3 = mysql_fetch_row($result);
$num_rows = mysql_num_rows($result);
$d4 = gmp_div_q("$num_rows", "2", GMP_ROUND_MINUSINF);
$d3 = gmp_div_q("$num_rows", "2", GMP_ROUND_PLUSINF);
$j = 1;
$result18 = mysql_query("SELECT * FROM name WHERE field4 = '$cat' ",$db);
while ($myrow3 = mysql_fetch_row($result18))
{
if ($j <= gmp_strval($d3))
{
$j=$j+1;
}
else
{
echo "<p>";
echo '<a href="detail.php?';
echo 'page=';
echo "$myrow3[2]";
echo '&';
echo 'pnum=';
echo "$myrow3[6]";
echo '">';
echo "$myrow3[1]";
echo "</p>";
$j = $j + 1;
}
}
?>

</div>
</td>
</tr>
</table>
</div>
4

1 回答 1

0

如果我读得好,您gmp_div_q仅用于四舍五入吗?然后,您应该检查round().

唯一round()不能覆盖的情况是GMP_ROUND_ZERO,但你不使用它(你可以用一个简单的 覆盖它if)。

于 2013-05-16T14:50:54.940 回答