簡體   English   中英

如何添加帶有表頭的圖像?

[英]how to add image with table header?

如何使用表格標題在不同時間顯示三幅圖像。 我有一個來自表頭的代碼以及用於顯示數據升序和降序以及鏈接的過濾器的鏈接。

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和其他未單擊的標題鏈接的相同現象將顯示無作用的圖像。

看起來您已經擁有使用值有條件顯示圖像所需的所有數據。 對於每個標題,您可以簡單地有條件地添加正確的圖像。

$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>';

我沒有測試過此代碼,但是它應該使您了解如何完成所需的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM