如何使用表格标题在不同时间显示三个图像。我有一个来自表头的代码以及用于以升序和降序显示数据的链接以及对它们进行过滤。
echo "<table width='100%'>
<tr>
<th><a href= 'http://192.168.0.49/intern/index.php?page=".$_GET["page"]."&date1=".$_GET["date1"]."&date2=".$_GET["date2"]. "&orderby=id&dir=".$dir."'>Id</th>
<th><a href= 'http://192.168.0.49/intern/index.php?page=".$_GET["page"]."&date1=".$_GET["date1"]."&date2=".$_GET["date2"]."&orderby=event_date&dir=".$dir."'>Event Date</a></th>
<th><a href= 'http://192.168.0.49/intern/index.php?page=".$_GET["page"]."&date1=".$_GET["date1"]."&date2=".$_GET["date2"]."&orderby=bdm_name&dir=".$dir."'>BDM Name</th>
<th><a href= 'http://192.168.0.49/intern/index.php?page=".$_GET["page"]."&date1=".$_GET["date1"]."&date2=".$_GET["date2"]."&orderby=event_type&dir=".$dir."'>Event Performed</th>
<th><a href= 'http://192.168.0.49/intern/index.php?page=".$_GET["page"]."&date1=".$_GET["date1"]."&date2=".$_GET["date2"]."&orderby=completed&dir=".$dir."'>Completed</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . date( "m/d/Y", strtotime($row['event_date'])) . "</td>";
echo "<td>" . $row['bdm_name'] . "</td>";
echo "<td>" . $row['event_type'] . "</td>";
echo "<td>" . $row['completed'] . "</td>";
echo "</tr>";
}
echo "</table>";
我使用条件
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
if($_REQUEST["dir"]=="" || $_REQUEST["dir"]=="desc")
$dir="asc";
else
$dir="desc";
if($_REQUEST["orderby"]!="")$ord = " ORDER BY ".$_REQUEST["orderby"];
if($_REQUEST["dir"]!="")$ord .= " ".$_REQUEST["dir"];
对于分页,我使用:
$page = (intval($_GET['page'])>0) ? $_GET['page'] : 2;
$recordPerPage= '30';
$startPoint = ($page - 1)*$recordPerPage;
$result = mysql_query("SELECT count(*) cnt FROM ` admin_crmf_poc_event_history` where $condition");
$row = mysql_fetch_array($result);
$num_rows = $row["cnt"];
$result = mysql_query("SELECT * FROM ` admin_crmf_poc_event_history` where $condition $ord LIMIT $startPoint,$recordPerPage");
$totalPages=ceil($num_rows/$recordPerPage);
对于asc而言,我要添加的图像对于来说是
,对于没有动作,我会看到
。这样,如果我点击desc的标题链接,desc图像将显示,并且asc和其他未点击的标题链接的相同现象显示无动作的图像。
答案 0 :(得分:0)
看起来您已经拥有了使用这些值有条件地显示图像所需的所有数据。对于每个标题,您只需有条件地添加正确的图像。
如
$headings = array(
'id' => 'Id',
'event_date' => 'Event Date',
'bdm_name' => 'BDM Name',
'event_type' => 'Event Performed',
'completed' => 'Completed'
);
$actionImages = array(
'noaction' => 'noaction.png',
'asc' => 'ascending.png',
'desc' => 'descending.png',
);
$currentDirection = $_REQUEST['dir'];
$defaultDirection = 'desc';
$orderByColumn = $_REQUEST['orderby'];
echo '<table width="100%"><tr>';
// For each heading, add to table
foreach ($headings as $column => $label) {
// Determine action image to show
if ($orderByColumn == $column) {
$actionImg = (!empty($currentDirection)) ? $actionImages[$currentDirection] : $actionImages[$defaultDirection];
} else {
$actionImg = $actionImages['noaction'];
}
echo '<th><img src="' . $actionImg . '">'
. '<a href="http://192.168.0.49/intern/index.php?page='
. $_GET['page'] . '&date1=' . $_GET['date1'] . '&date2=' . $_GET['date2']
. '&orderby=' . $column . '&dir=' . $dir . '">'
. $label . '</th>';
}
echo '</tr>';
我还没有对这段代码进行测试,但它应该让您了解如何完成您正在寻找的内容。