2016-06-23 5 views
-1

私が他の投稿に書いたように、私はAjaxとjQueryで充分な知識がありませんので、ここでは少し助けが必要です..私はすでに記事(各ページに2つの記事 - 現在は5ページが表示されています)がありますが、データベーステーブルから記事情報を取得したいと思います。これを行うにはAjaxが必要です。記事のためのページの変更で、AjaxとjQueryを使用してデータベーステーブルから情報を取得する

コード:

<div id="slider"> 
    <div id="slider-wrapper"> 
    <div id="slide"> 
    <div class="row top-buffer"> 
      <div class="col-md-6"> 
      <img class="img-rounded" src="img/strawberry-wallpaper.jpg" alt="MyImage" width="550px" height="240px"> 
       </div> 
     <div class="col-md-6"> 
     <h3>Title</h3> 
          <p class="well">Some Title...<p> 

            <div class="row top-buffer"> 

             <div class="col-md-5 col-md-offset-1"> 
             <img src="img/link_icon.png" class="img-rounded" width="20px" height="20px"/> 
             <a href="#">Link</a> 
             </div> 
             <div class="col-md-6"> 

           <button class="btn btn-primary pull-right" id="btn">Read More</button> 



         </div> 
        </div> 
       </div> 
      </div> 
      . 
      . 
      . 
</div> 
<div id="slider-nav"> 
    <a href="#" data-slide="0">1</a> 
    <a href="#" data-slide="1">2</a> 
    <a href="#" data-slide="2">3</a> 
    <a href="#" data-slide="3">4</a> 
    <a href="#" data-slide="4">5</a> 
</div> 

+0

あなたはPHPを使用していますか? 。ネット?あなたのクライアントにコンテンツを返すのですか? – fictus

+0

私はPHPを使用しています! – platanas20

答えて

1

は、私は同様の改ページを行なったし、見て本当にあなたが//

<?php if (isset($patientBills['rows']) && !empty($patientBills['rows'])) { ?> 

    <table class="ui cell striped table"> 
     <thead> 
      <tr> 

       <th rowspan="2">Bill No</th> 
       <th rowspan="2">Bill Date & Time</th> 
      </tr> 

     </thead> 
     <tbody> 
      <tbody> 
       <?php $rowindex =1;  foreach ($patientBills['rows'] as $bill) { 
     ?> 
        <tr> 
         <td> 
          <a title="View Bill" href="<?php echo BILLING_PATH . 'patient/' . $bill['patient_id'] . '/' . $rowindex * $page; ?>"> 
           <?php echo $bill['bill_no']; ?> 
          </a> 
         </td> 
         <td> 
          <?php $date=date_create($bill['paid_date']); echo date_format($date, DATE_FORMAT); ?> 
         </td> 

        </tr> 
        <?php } ?> 

      </tbody> 
     </tbody> 
<?php if ($patientBills['totalpages'] > 1) { ?> 
     <tfoot> 
      <tr> 
       <th colspan="9"> 
        <div class="ui floated right border pagination menu "> 
         <a id="previousbtn" name="pageNavbtn" class="<?php echo $patientBills[ 'page']==1 ? 'disabled': ''; ?> item"> 
          <i class="left arrow icon"></i> Previous </a> 
         <?php 
          $startPage = 1; 
          $loop = 0; 
          if ($patientBills['page'] > NO_OF_PAGES) { 
           $startPage = $patientBills['page'] - NO_OF_PAGES + 2; 
          } 
          for ($pag = $startPage; $pag <= $patientBills["totalpages"]; $pag++) { $loop ++?> 
          <a href="#" class="<?php echo $patientBills['page']== $pag ? 'disabled': ''; ?> item" name="patientPageLink" id="<?php echo $pag; ?>"> 
           <?php echo $pag; ?> 
          </a> 
          <?php $loop == NO_OF_PAGES ? $pag = $patientBills["totalpages"] + 1:''; ?> 
           <?php } 
        if ($patientBills["totalpages"] > NO_OF_PAGES) { ?> 
            <a id="nextPagebtn" name="pageNavbtn" class="<?php echo $patientBills['page'] == $patientBills['totalpages'] ? 'disabled':''; ?> item">Next&nbsp; 
         <i class="icon right arrow"></i></a> 
            <?php } ?> 
        </div> 
       </th> 
      </tr> 
     </tfoot> 
<?php } ?> 
    </table> 
    <?php } else {?> 
No bills created for this patient. 
<?php } ?> 

     <script> 



      $('a[name=pageNavbtn], a[name=patientPageLink]').click(function() { 
       var currentPage = <?php echo $patientBills['page']; ?>; 
       var totalpages = <?php echo $patientBills['totalpages']; ?>; 
       if (this.id == 'previousbtn') { 
        if (currentPage > 1) { 
         currentPage -= 1; 
        } 
       } else if (this.id == 'nextPagebtn') { 
        if (currentPage < totalpages) { 
         currentPage += 1; 
        } 
       } else { 
        currentPage = this.id; 
       } 
       var postData = { 
        page: currentPage 
        , patientId: <?php echo $patientId;?> 
       }; 
       var Url = "<?php echo PATIENT_PATH . GET_BILL_LIST_BY_PAGENO; ?>"; 
       triggerAjaxPost(Url, postData, function (resdata) { 
        $('#billlistcontainer').html(resdata); 
       }); 
      }); 

     </script> 

役立ちますresdataは、html形式

に建設されます
// DB Query 
$count_query = " 
       SELECT 
        COUNT(*) as count 
       FROM 
        patient_billing 
        WHERE 
        patientid = " . $patientid; 

     $result_count = mysqli_query($this->_connection, $count_query); 
      $rowcount = mysqli_fetch_array($result_count); 
      $count = $rowcount['count']; 
      $limit = $this->_limit; 
      $page = $this->_page; 
      $sidx = $this->_sidx; 
      $sort = $this->_sort; 
    $sortBy = $this->_sidx; 
    if (empty($sort)){ 
     $sort = 'desc'; 
    } 
    if (empty($limit)){ 
     $limit = 1; 
    } 
    if (empty($page)){ 
     $page = 1; 
    } 
     if (empty($sortBy)){ 
     $sortBy = ' bill_no '; 
    } 

     if($count > 0 && $limit > 0) { 
      $total_pages = ceil($count/$limit); 
     } else { 
      $total_pages = 0; 
     } 
     if ($page > $total_pages) $page=$total_pages; 

     $start = $limit * $page - $limit; 

     if($start <0) $start = 0; 

     $query  = " 
        SELECT 
        * 
       FROM 
        patient_billing 
        WHERE 
        patientid = " . $patientid . " " . 
      " ORDER BY " . $sortBy . " " . $sort 
      . " LIMIT " . $start .",". $limit; 
    $result = mysqli_query($this->_connection, $query) or die("Couldn't execute query: " . mysqli_error($this->_connection)); 

     if (mysqli_num_rows($result) > 0) { 
      while ($row = mysqli_fetch_assoc($result)) {     
       $responce[] = $row; 
      } 
     } 

    $patientBills= array("totalpages"=>$total_pages, "page"=>$page, "records"=>$count, "rows"=>$responce); 
+0

私はまずそれを理解する必要があります。それは私のためにちょっと難しいです。そのような経験はありません。あなたの答えは役に立つでしょう! – platanas20

+0

ありがとう.. :-)あなたがどこにいてもコメントしてください。 –

+0

私はそれを行うでしょう..再び感謝します! – platanas20

関連する問題