我有一个显示来自MySQL数据库的记录。目前我把它设置为一个表,重复区域显示总共6个条目。
我希望这个重复到右边,制作两列,即左边的一个表显示记录1~6,右边的一个表显示记录7~12。我真的很重视任何帮助你可以给...谢谢x
我的HTML是:
<table width="600" border="0">
<?php do { ?>
<tr>
<td><?php echo $row_glossary_main['term']; ?>:</td>
<td><?php echo $row_glossary_main['definition']; ?></td>
</tr>
<?php } while ($row_glossary_main = mysql_fetch_assoc($glossary_main)); ?>
</table>
页面的php是:
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_glossary_main = 6;
$pageNum_glossary_main = 0;
if (isset($_GET['pageNum_glossary_main'])) {
$pageNum_glossary_main = $_GET['pageNum_glossary_main'];
}
$startRow_glossary_main = $pageNum_glossary_main * $maxRows_glossary_main;
mysql_select_db($database_ships, $ships);
$query_glossary_main = "SELECT * FROM glossary_main ORDER BY term ASC";
$query_limit_glossary_main = sprintf("%s LIMIT %d, %d", $query_glossary_main, $startRow_glossary_main, $maxRows_glossary_main);
$glossary_main = mysql_query($query_limit_glossary_main, $ships) or die(mysql_error());
$row_glossary_main = mysql_fetch_assoc($glossary_main);
if (isset($_GET['totalRows_glossary_main'])) {
$totalRows_glossary_main = $_GET['totalRows_glossary_main'];
} else {
$all_glossary_main = mysql_query($query_glossary_main);
$totalRows_glossary_main = mysql_num_rows($all_glossary_main);
}
$totalPages_glossary_main = ceil($totalRows_glossary_main/$maxRows_glossary_main)-1;
?>
答案 0 :(得分:1)
将所有结果放入数组
$resultrow=array();
while ($row_glossary_main = mysql_fetch_assoc($glossary_main))
{$resultrow=$row_glossary_main; }
计算数组$ resultrow
的总数然后你必须输出
$count=count($resultrow)/2;
for($i=0;$i<$count;$i++)
{
<td>$resultrow[$i]</td><td>$resultrow[$count*2-1]</td>
}