我的动态表不断重复每个新数据库条目的标题

时间:2014-02-04 18:06:09

标签: php html mysql content-management-system dreamweaver

我正在尝试使用Dreamweaver cs5中的重复区域创建动态表,但不幸的是,在浏览器上查看时,每个新记录条目也会重复标题。

  • 公司参考日期     海布里223333 2014-02-01     公司参考日期     安菲尔德223335 2014-02-03    公司参考日期     trafford 223336 2014-02-02

我怎样才能让表格只显示一次标题,下面有相应的条目? 即,

  • 公司参考日期     海布里223333 2014-02-01     安菲尔德223334 2014-02-03     trafford 223336 2014-02-02

这是html / php标记。

<?php require_once('Connections/connect.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;
}
}

mysql_select_db($database_connect, $connect);
$query_field = "SELECT * FROM field";
$field = mysql_query($query_field, $connect) or die(mysql_error());
$row_field = mysql_fetch_assoc($field);
$totalRows_field = mysql_num_rows($field);
?>

<?php do { ?>
  <table class="table table-hover table-nomargin">
    <thead>
      <tr>
       <th>Company</th>
       <th>Ref No.</th>
       <th>Date</th>
      </tr>
    </thead>
    <tbody>
     <tr>
      <td><?php echo $row_field['i_company']; ?></td>
      <td><?php echo $row_field['i_ref']; ?></td>
      <td><?php echo $row_field['i_date']; ?></td>
     </tr>
    </tbody>
  </table>
 <?php } while ($row_field = mysql_fetch_assoc($field)); ?>

2 个答案:

答案 0 :(得分:0)

您需要将do while语句移动到表记录...

 <table class="table table-hover table-nomargin">
    <thead>
      <tr>
       <th>Company</th>
       <th>Ref No.</th>
       <th>Date</th>
      </tr>
    </thead>
    <tbody>
<?php do { ?>
     <tr>
      <td><?php echo $row_field['i_company']; ?></td>
      <td><?php echo $row_field['i_ref']; ?></td>
      <td><?php echo $row_field['i_date']; ?></td>
     </tr>
 <?php } while ($row_field = mysql_fetch_assoc($field)); ?>
    </tbody>
  </table>

答案 1 :(得分:0)

您的Do / While函数告诉第一行带有标题,以便在数据库中找到它的每一行。尝试将Do / While函数包装在仅包含变量的行周围,如下所示:

<table class="table table-hover table-nomargin">
<thead>
  <tr>
   <th>Company</th>
   <th>Ref No.</th>
   <th>Date</th>
  </tr>
</thead>
<tbody>

<?php do { ?>
 <tr>
  <td><?php echo $row_field['i_company']; ?></td>
  <td><?php echo $row_field['i_ref']; ?></td>
  <td><?php echo $row_field['i_date']; ?></td>
 </tr>
<?php } while ($row_field = mysql_fetch_assoc($field)); ?>

</tbody>
</table>

这样它就会在该行上重复,而不是重复标题。