我正在尝试使用 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/