Php 如何添加带有表头的图像?
如何使用表格标题在不同时间显示三个图像。我有一个表头的代码,以及以升序和降序显示数据的链接,并对它们进行过滤Php 如何添加带有表头的图像?,php,html,mysql,pagination,Php,Html,Mysql,Pagination,如何使用表格标题在不同时间显示三个图像。我有一个表头的代码,以及以升序和降序显示数据的链接,并对它们进行过滤 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"].
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>";
对于分页,我使用:
$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的标题链接,desc图像将显示,asc和其他未单击的标题链接的相同现象将显示无操作的图像。看起来您已经拥有使用这些值有条件地显示图像所需的所有数据。对于每个标题,只需有条件地添加正确的图像 比如
$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>';
$headers=数组(
'id'=>'id',
“事件日期”=>“事件日期”,
'bdm_name'=>'bdm name',
“事件类型”=>“已执行事件”,
“已完成”=>“已完成”
);
$actionImages=array(
'noaction'=>'noaction.png',
'asc'=>'升序.png',
'desc'=>'descending.png',
);
$currentDirection=$_请求['dir'];
$defaultDirection='desc';
$orderByColumn=$_请求['orderby'];
回声';
//对于每个标题,添加到表中
foreach($列的标题=>$标签){
//确定要显示的动作图像
如果($orderByColumn==$column){
$actionImg=(!empty($currentDirection))?$actionImages[$currentDirection]:$actionImages[$defaultDirection];
}否则{
$actionImg=$actionImages['noaction'];
}
回声“
. ''
.$标签';
}
回声';
我还没有测试过这段代码,但它应该能让您了解如何实现所需的功能
$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>';