首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >2列中的记录集重复区域

2列中的记录集重复区域
EN

Stack Overflow用户
提问于 2013-07-08 02:47:56
回答 1查看 855关注 0票数 0

我有一个显示来自MySQL数据库的记录。目前,我将其设置为一个表格,其中的重复区域显示了总共6个条目。

我想把这个重复到右边,做两列,即左边一个表格显示记录1~6,右边一个表格显示记录7~ 12。我真的很感谢你能给我的任何帮助…谢谢你x

我的HTML是:

代码语言:javascript
复制
<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是:

代码语言:javascript
复制
<?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;
?>
EN

回答 1

Stack Overflow用户

发布于 2013-07-08 03:07:13

将所有结果放入数组中

代码语言:javascript
复制
$resultrow=array();
while ($row_glossary_main = mysql_fetch_assoc($glossary_main))
  {$resultrow=$row_glossary_main; }

统计数组$resultrow总数

然后在你必须输出的地方

代码语言:javascript
复制
$count=count($resultrow)/2;
  for($i=0;$i<$count;$i++)
     {
       <td>$resultrow[$i]</td><td>$resultrow[$count*2-1]</td> 
     }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17515181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档