S
S
svilkov872016-10-21 15:25:41
PHP
svilkov87, 2016-10-21 15:25:41

Count number of cells in db using PDO?

Good afternoon!
There is a table:
36f3faa625a94ad6a93ab7a1cc8aeedb.jpg
$_GET contains data that corresponds to the number in the "user_id" column.
The query structure starts like this:

if(!empty($_GET)) {

    $id = intval($_GET['id']);
    
    //здесь должен быть запрос PDO в БД
}

How to form a query that will return the number (number) of records where user_id corresponds to $id?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2016-10-21
@svilkov87

$st = $pdo->prepare('SELECT COUNT(user_id) as cnt FROM `article` WHERE user_id=:user_id');
$st->bindParam(':user_id', $id, PDO::PARAM_INT);
$art_column = $st->fetch();
$st->execute();
$data = $st->fetch();
echo $data['cnt']; // выводим количество

D
display: block, 2016-10-21
@qork

SELECT count(user_id) FROM tablitsa WHERE user_id = '$id'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question