2016-04-03 19 views
1

gelen kayıtların sayısını gösteriliyor ben veritabanından kayıtları silmek için böyle bir şey kullanın:,veritabanından

// did user press submit 
if($_SERVER['REQUEST_METHOD'] == 'POST'){ 
// what button did they press 
if (isset($_POST['delete'], $_POST['id'])) { 
    // we have been request to delete 
    // and we have an id to control the delete 

    // instantiate the class we need 
    $cat = new Category($conn); 

    // clean up our input before we us it in a SQL query 
    $id = filter_input (INPUT_POST , 'id', FILTER_SANITIZE_NUMBER_INT); 

    // call the method we want to run 
    $cat->deleteSelected($id); 
} 
} 
?> 


<form action="" method="post"> 
<label>Category id :</label> 
<input type="text" name="id" id="id" required="required" placeholder="Please  Enter Id"/><br /><br /> 
<input type="submit" value="Delete" name="delete"/><br /> 
</form> 

Şimdi ne yapmak istiyorum bu fonksiyonu kullanarak bir veritabanından kayıt sayısını göstermektir:

// countAll(): This function will count all the categories and return it. 
public function countAll() { 
    $query = 'SELECT * FROM categories'; 

    $stmt = $this->conn->prepare($query); 
    $stmt->execute(); 
    $count = $stmt->rowCount(); 

    return $count; 
} 

Düğmeye tıkladıktan sonra kategori tablosundaki kayıt miktarını görüntülemesini sağlamak için ilk kodda (veya ikinci bölümde) değiştirmek zorundayım?

cevap

2

Bunun countAll() sonucunu yankı

<?php 
    echo countAll(); 

    public function countAll() { 
    $query = 'SELECT * FROM categories'; 

    $stmt = $this->conn->prepare($query); 
    $stmt->execute(); 
    $count = $stmt->rowCount(); 

    return $count; 
} 
?> 
İlgili konular