/ / CodeIgniter MySQL अलग-अलग पंक्तियों को गिनता है - php, mysql, codeigniter

CodeIgniter MySQL अलग-अलग पंक्तियों को गिनता है - php, mysql, codeigniter

मैं CodeIgniter में विभिन्न पंक्तियों को गिनना चाहता हूँ ...

मेरे पास इस तरह की एक टेबल है

NAME | ZIPCODE
Mike | 12345
Marc | 51233
TEST | 12345

अब मैं "2" का परिणाम चाहता हूं क्योंकि 2 अलग-अलग ज़िपकोड हैं।

मैंने बहुत कोशिश की, लेकिन यह नहीं मिला :(

$this->db->select("zipcode, count(*)");
$getAll = $this->db->get("ads");
echo $getAll->num_rows();

लेकिन न तो परिणाम या कुछ भी ... idk कैसे मैं यह कर सकते हैं। कृपया सहायता कीजिए

// संपादित करें: ठीक है मैंने पाया। प्रश्न के लिए क्षमा करें। यहाँ उत्तर है

$this->db->distinct();
$this->db->select("zipcode");
$getAll = $this->db->get("ads");
echo $getAll->num_rows();

उत्तर:

जवाब के लिए 0 № 1

आप इसका उपयोग कर सकते हैं:

$query = $this->db->query("select count(1) as x from your_table_name group by zipcode");

$row= $query->row();
$x = $row->x;

जवाब के लिए 0 № 2

आप अपनी क्वेरी में group_by () का उपयोग इस प्रकार कर सकते हैं।

$this->db->select("zipcode", "count(*) as totalcount");
$this->db->group_by("zipcode");
$this->db->get("ads");