How can I list one row and total number of each category

Hi,
Each company has more than one record in the “teklif” table
How can I show the information and total number of each company on a single line separately?
My aim is to show the number of companies from largest to smallest (such as statistics)

Company information is

  1. Company authorized Name Surname
  2. Company Name
  3. Total Registration of the Firm

Sample
Adem GENÇ --|-- Company --|-- 7
Ahmet SAYDAM --|-- Company --|-- 5
as

I want to show this information in pagination system

if(isset($_POST['per'])){
    $limit = $_POST['per'];
}
else
{
    $limit = '10';
}

$sql = 'SELECT
teklif.name_surname,
members.company
FROM teklif
LEFT JOIN members ON teklif.member_id = members.member_id
ORDER BY members.company DESC ';

$page = 1;
$start = 0;
if(!empty($_POST["page"])) {
  $page = $_POST["page"];
  $start = ($page-1) * $limit;
}
$limit_code = " LIMIT " . $start . "," . $limit;
$pagination_statement = $PDOdb->prepare($sql);
$pagination_statement->execute();

$top_row = $pagination_statement->rowCount();

$query = $sql.$limit_code;
$pdo_statement = $db->prepare($query);
$pdo_statement->execute();
$companyarray = $pdo_statement->fetchAll();

I tried to do something like above but for pagination I want it to count each group once instead of counting each row

I tried to do something like below, I listed one from each group, but since the pagination system counts each row, the number of rows listed is 2 while the second page occurred in the pagination

$companyarray = $pdo_statement->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_COLUMN);

foreach ($companyarray as $name_surname => $company) {
	echo "Name Surname: ".$name_surname." Company: ".$company." Total rows: ".count($company)."<br>";
}

I will be glad if you help
Thank you from now

Perhaps something like this:

SELECT CompanySurname, CompanyName, count(CompanyName) FROM teklif WHERE name LIKE '%xxxxxxx%';

or
maybe

SELECT CompanySurname, CompanyName, count(CompanyName) FROM teklif WHERE name !='' GROUP BY CompanyName;

Obviously replace the ‘xxxxx’ string with the company name you are looking for in the first query

1 Like

Thank you for the answer,

How easy it was, I tried it, now I will apply it in real place
It’s so hard when we don’t know :grinning:

edit:
Worked perfectly in real place
Thank you again

Sponsor our Newsletter | Privacy Policy | Terms of Service