A
A
Alexey2021-09-01 18:25:27
PHP
Alexey, 2021-09-01 18:25:27

How can I get from the database the number of records in which the list value is equal to element 1?

Hello. I'll try to explain more clearly. There is a database, it has a table with records. Each entry contains a value from the list - 1, 2 or 3. I connected to the database and got the total number of entries in the table:

$sql = "SELECT * FROM cms_con_ls";
if($result = $conn->query($sql)){
    $rowsCount = $result->num_rows;


Thus I displayed the total number of records. How can I now make a correct database query to display only the number of records in which the list value is 1?

612f9b5147a25922545018.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Volodymyr Palamar, 2021-09-01
@urinov

SELECT COUNT(*) FROM cms_con_ls WHERE status=1

A
Alexey, 2021-09-01
@urinov

In general, he did.

$conn = new mysqli("localhost", "пользователь", "пароль", "база");
$alls = $conn->query("SELECT COUNT(*) FROM cms_con_ls WHERE status=1");
$row = $alls->fetch_row();
$allso = $row[0];
echo $allso;

now it works as it should. Thanks everyone for the tips

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question