Hello! The function receives a parameter through the address bar and makes a selection from the database. If I enter the request with specific numbers in phpmyadmin, then the request displays what you need. And the function returns an empty array:
function article_block($category){ try { $dsn = sprintf('mysql:host=%s;dbname=%s;charset=utf8', HOST, DB); $pdo = new PDO($dsn, USER, PASS); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo "<p>Запрос на выборку данных из бызы не прошёл. Напишите об этом администратору <a href='mailto:admin@torawhite.ru'>admin@torawhite.ru</a>.</p><br>ERROR: " . $e->getMessage(); exit; } $sql = '(SELECT article_id, article_cat_id, article_par_id, article_title, article_img, article_author, article_author_card, article_description, article_date, article_views FROM articles WHERE article_cat_id = :cat) UNION (SELECT article_id, article_cat_id, article_par_id, article_title, article_img, article_author, article_author_card, article_description, article_date, article_views FROM articles WHERE article_cat_id IN ( SELECT cat_id FROM magazine_left_sidebar WHERE parent_id = :cat ))'; $data = $pdo->prepare($sql); $data->bindValue (':cat', $category); $data->execute(); $article_block = $data->fetchAll(PDO::FETCH_ASSOC); return $article_block; } I can not understand what's wrong ...
$data->bindValue (':cat', $category, PDO::PARAM_INT);In general, you can exclude bindValue:$data->execute(array(":cat"=>$category));And what if, after$data->executeto makevar_dump($data)- see what is there to extract? - Boris