<?php
$id=$_POST['itinerary_id'];
$query=mysql_query("select * from tblitinerarydetails where tblid='$id' order by date_of_travel asc");
$i = 0;
$prevValue = NULL;
while($rows=mysql_fetch_array($query)){
$date=$rows['date_of_travel'];
$mydate = strtotime($date);
$newdate = date('F j, Y', $mydate);
$activities=$rows['activities'];
$time_departure=$rows['time_departure'];
$time_arrival=$rows['time_arrival'];
$new_time_departure = date('g:i A', strtotime( $time_departure));
$new_time_arrival = date('g:i A', strtotime( $time_arrival));
$means_of_transportation= $rows['means_of_transportation'];
$travelling_allowance = number_format($rows['travelling_allowance'],2);
$destination = $rows['destination'];
$i++;
echo "<tr>";
if ($newdate == $prevValue) {
echo "<td align='left' rowspan='$i'>$prevValue</td>";
}
$prevValue = $newdate;
echo "<td align='left'>$destination</td>";
echo "<td align='center'>$new_time_departure</td>";
echo "<td align='center'>$new_time_arrival</td>";
echo "<td align='center'>$activities</td>";
echo "<td align='center'>$means_of_transportation</td>";
echo "<td align='right'>$travelling_allowance</td>";
echo "</tr>";
}
?>
如果值相同,我只想在表格中添加rowspan。让我们这样说:
我希望2月4日的所有日期都是小组,并且只会发生一次(rowspan)。
答案 0 :(得分:1)
尝试使用jQuery -
<table border=1 id="myTable">
<tr>
<td>A</td>
<td>1</td>
</tr>
<tr>
<td>A</td>
<td>2</td>
</tr>
<tr>
<td>b</td>
<td>1</td>
</tr>
<tr>
<td>c</td>
<td>1</td>
</tr>
<tr>
<td>c</td>
<td>1</td>
</tr>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
$(document).ready(function() {
var span = 1;
var prevTD = "";
var prevTDVal = "";
$("#myTable tr td:first-child").each(function() { //for each first td in every tr
var $this = $(this);
if ($this.text() == prevTDVal) { // check value of previous td text
span++;
if (prevTD != "") {
prevTD.attr("rowspan", span); // add attribute to previous td
$this.remove(); // remove current td
}
} else {
prevTD = $this; // store current td
prevTDVal = $this.text();
span = 1;
}
});
});
<强>输出强>
答案 1 :(得分:0)
它可以用作文本,但不能与
一起使用<img src='picture/".$row["j_pic"]."' width='90' height='90' border='0' />
如何?