php - 如何在表格标题中添加图像?

标签 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"].         "&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);

我想添加的图像看起来像 enter image description here说明 enter image description here对于 asc 和 enter image description here没有任何行动。这样,如果我单击 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>';

我还没有测试过这段代码,但它应该能让您了解如何实现您正在寻找的目标。

关于php - 如何在表格标题中添加图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23154174/

相关文章:

php - 表单和 Action 在同一页面或不同页面

php - MYSQL 更新查询无法完成

php - 如何获取 Laravel 查询生成器返回非关联结果

php - 使用文本区域将复制和粘贴的文本发布到数据库中不起作用

c# - 使用 MySqlDataReader 无法正确查询

java - php pack ('H*' ,$securesecret) 等价于 Java

php - 在php中将mysql导出到excel中的模板

javascript - 动态地将输入控件添加到 jQuery DataTables

html - DIV 在有子元素时移动

javascript - 检测浏览器的 native 日期/时间选择器