0

MySQL データベースからのレコードを表示するものがあります。現時点では、繰り返し領域に合計 6 つのエントリが表示されたテーブルとして設定しています。

これを右側に繰り返して、2 つの列を作成します。つまり、左側の 1 つのテーブルにレコード 1 ~ 6 を表示し、右側の 1 つのテーブルにレコード 7 ~ 12 を表示します。 ...ありがとう×

私の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;
?>
4

1 に答える 1

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> 
     }
于 2013-07-07T19:07:12.730 に答える