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

标签 php html mysql content-management-system dreamweaver

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

  • 公司引用日期 海布里 223333 2014-02-01 公司引用日期 安菲尔德 223335 2014-02-03 公司引用日期 特拉福德223336 2014-02-02

如何让表格仅显示一次标题及其下方的相应条目? 即,

  • 公司引用日期 海布里 223333 2014-02-01 安菲尔德 223334 2014-02-03 特拉福德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)); ?>

最佳答案

您需要将 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>

关于php - 我的动态表不断重复每个新数据库条目的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21560045/

相关文章:

PHP/CSS/HTML 网络导航在 Chrome 中充当图像

PHP/MySQL 面试 - 你会如何回答?

mysql - 插入触发器之前的 SQL

php - 使用 PHP 获取 PDF 文件中的字段

javascript - 是否可以将 ASCII 艺术添加到 javascript 弹出窗口?

php - Magento 将产品从一个数据库复制到另一个数据库

mysql - 添加触发器以从 Amazon Aurora 调用 Lambda 函数不起作用

PHP 相当于 JavaScript 的 parseInt 函数?

html - asp.net mvc web 应用程序中我的 Razor View 的响应式设计

javascript - 使用 document.createElement 创建嵌套标签