2017-02-17 91 views
-1

花費了幾個小時試圖弄清楚這一點,但不是一個好的編碼器。我有2個稱爲標題和日期的標題,我試圖阻止它們在每行之前重複。我只想把標題放在頂部。我有什麼需要改變來完成這一點。謝謝!!!!使用比特幣進行搜索。如何刪除重複的標題

<thead> 
     <tr> 
      <th class='table-header' width='20%'>Title</th> 
      <th class='table-header' width='5%'>Date</th> 
     </tr> 
     </thead> 



<?php 
define("ROW_PER_PAGE",15); 
require_once('db.php'); 
?> 
<html> 
<head> 
<style> 
body{width:615px;font-family:arial;letter-spacing:1px;line-height:20px;} 
.tbl-qa{width: 100%;font-size:0.9em;background-color: #f5f5f5;} 
.tbl-qa th.table-header {padding: 5px;text-align: left;padding:10px;} 
.tbl-qa .table-row td {padding:10px;background-color: #FDFDFD;vertical-align:top;} 
.button_link {color:#FFF;text-decoration:none; background-color:#428a8e;padding:10px;} 
#keyword{border: #CCC 1px solid; border-radius: 4px; padding: 7px;background:url("demo-search-icon.png") no-repeat center right 7px;} 
.btn-page{margin-right:10px;padding:5px 10px; border: #CCC 1px solid; background:#FFF; border-radius:4px;cursor:pointer;} 
.btn-page:hover{background:#F0F0F0;} 
.btn-page.current{background:#F0F0F0;} 
</style> 
</head> 
<body> 
<?php 
    $search_keyword = ''; 
    if(!empty($_POST['search']['keyword'])) { 
     $search_keyword = $_POST['search']['keyword']; 

    $sql = 'SELECT * FROM posts WHERE post_title LIKE :keyword OR description LIKE :keyword OR post_at LIKE :keyword ORDER BY id DESC '; 

    /* Pagination Code starts */ 
    $per_page_html = ''; 
    $page = 1; 
    $start=0; 
    if(!empty($_POST["page"])) { 
     $page = $_POST["page"]; 
     $start=($page-1) * ROW_PER_PAGE; 
    } 
    $limit=" limit " . $start . "," . ROW_PER_PAGE; 
    $pagination_statement = $pdo_conn->prepare($sql); 
    $pagination_statement->bindValue(':keyword', '%' . $search_keyword . '%', PDO::PARAM_STR); 
    $pagination_statement->execute(); 

    $row_count = $pagination_statement->rowCount(); 
    if(!empty($row_count)){ 
     $per_page_html .= "<div style='text-align:center;margin:20px 0px;'>"; 
     $page_count=ceil($row_count/ROW_PER_PAGE); 
     if($page_count>1) { 
      for($i=1;$i<=$page_count;$i++){ 
       if($i==$page){ 
        $per_page_html .= '<input type="submit" name="page" value="' . $i . '" class="btn-page current" />'; 
       } else { 
        $per_page_html .= '<input type="submit" name="page" value="' . $i . '" class="btn-page" />'; 
       } 
      } 
     } 
     $per_page_html .= "</div>"; 
    } 


    $query = $sql.$limit; 
    $pdo_statement = $pdo_conn->prepare($query); 
    $pdo_statement->bindValue(':keyword', '%' . $search_keyword . '%', PDO::PARAM_STR); 
    $pdo_statement->execute(); 
    $result = $pdo_statement->fetchAll(); 
} 
?> 
<form name='frmSearch' action='' method='post'> 
<div style='text-align:right;margin:20px 0px;'><input type='text' name='search[keyword]' value="<?php echo $search_keyword; ?>" id='keyword' maxlength='25'></div> 

    <?php 
    if(!empty($result)) { 
     foreach($result as $row) { 
    ?> 
<table class='tbl-qa'> 


<thead> 
    <tr> 
     <th class='table-header' width='20%'>Title</th> 
     <th class='table-header' width='5%'>Date</th> 
    </tr> 
    </thead> 


    <tbody id='table-body'> 
     <tr class='table-row'> 
     <td><a style="text-decoration: none;" href="<?php echo $row['description']; ?>"> 
    <?php echo $row['post_title']; ?></a></td> 
    <td><?php echo $row['post_at']; ?></td> 
     </tr> 
    <?php 
     } 
    } 
    ?> 
    </tbody> 
</table> 

<?php echo $per_page_html; ?> 

</form> 
</body> 
</html> 
+0

你重新創建表中的foreach循環(

... ),它應該只包括HTML你行( ...部分) –

+1

表需要循環 –

回答

0

這樣就會作品:

陣列測試(在你的情況下,使用您的$結果)

$result=array(
array('post_title'=>'title 1','post_at'=>'at 1'), 
array('post_title'=>'title 2','post_at'=>'at 2'), 
array('post_title'=>'title 3','post_at'=>'at 3'), 
) 

HTML:

<table class='tbl-qa'> 
<tr> 
    <th class='table-header' width='20%'>Title</th> 
    <th class='table-header' width='5%'>Date</th> 
</tr> 
<?php 
    if(!empty($result)) { 
     foreach($result as $row) { 
     ?> 
     <tr class='table-row'> 
      <td><a style="text-decoration: none;" href="<?php echo $row['description']; ?>"> 
      <?php echo $row['post_title']; ?></a></td> 
      <td><?php echo $row['post_at']; ?></td> 
     </tr> 
     <?php 
     } 
    ?> 
    <?php 
    } 
?> 

由於你可以看到,如果只是書面的頭一次是因爲它不在循環中,而循環內部的行將被重複。 最後關閉表中的循環。

+0

解析錯誤外:語法錯誤,意外$ end in /home/a8814009/public_html/index.php on line 107 – vinman64

+0

我不知道你是第107行。 我的代碼只有28行,它工作正常。我還添加了一個數組,以便測試它。 –

+0

謝謝賈科莫還有1個問題。標題和數據標題在我進行搜索之前顯示出來。看看我的意思是在http://vince.netau.net如果嘗試搜索使用術語比特幣 – vinman64