Answer the question
In order to leave comments, you need to log in
How to pull data from joined tables when they are linked in phpAdmin?
The crux of the matter is that I want to make categories. They are on a Pink background over the image. But id_category is displayed instead of category itself . I don't know how to fix it.
Here is a screenshot of how it is now.
Here is the code that calls $post['id_category'] , which I understand is not needed through the $post variable ? Potmou what is it in another table? (screenshots of the function below). Well, there is also a correctly working $post['image'] .
<div class="categor">
<?=$post['id_category']?>
</div>
<img src="<?=$post['image']?>" alt="">
function get_categories(){
global $link; // глобальная переменная из глобальной области видимости
$sql = "SELECT * FROM category";
$result = mysqli_query($link, $sql);
$categories = mysqli_fetch_all($result, MYSQLI_ASSOC);
return $categories;
}
function get_categories_by_id($category) {
global $link;
$sql = "SELECT * FROM category WHERE category=".$category;
$result = mysqli_query($link, $sql);
$categories = mysqli_fetch_all($result, MYSQLI_ASSOC);
return $categories;
}
function det_posts() {
global $link;
$sql = "SELECT * FROM posts";
$result = mysqli_query($link, $sql);
$posts = mysqli_fetch_all($result, MYSQLI_ASSOC);
return $posts;
}
<?php $posts = det_posts(); ?>
<?php foreach($posts as $post): ?>
<?php endforeach; ?>
Answer the question
In order to leave comments, you need to log in
Try to change
<div class="categor">
<?=$post['category']?>
</div>
<img src="<?=$post['image']?>" alt="">
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question