SELECT COUNT(id_user) as counter
FROM $table_questions WHERE id_user = :id_user1
UNION
SELECT COUNT(id_user) as counter
FROM $table_marketplace WHERE id_user = :id_user2
UNION
SELECT COUNT(id_user) as counter
FROM $table_jobs WHERE id_user = :id_user3
Will return 3 rows each with the count, you have to give all the counts the same alias.
If you want to maybe identfy each result row specifically add another column as an identifier
SELECT 'Questions' as what, COUNT(id_user) as counter
FROM $table_questions WHERE id_user = :id_user1
UNION
SELECT 'Marketplace' as what, COUNT(id_user) as counter
FROM $table_marketplace WHERE id_user = :id_user2
UNION
SELECT 'Jobs' as what, COUNT(id_user) as counter
FROM $table_jobs WHERE id_user = :id_user3
Will give something like
what count
Questions 7
Marketplace 9
Jobs 3
And you can retrieve them as
$array = $stmt->fetch_all();
You will get an array like
Array
(
[Questions] => 7
[Marketplace] => 9
[Jobs] => 3
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…