E
E
Elizabeth2017-06-11 16:45:52
PHP
Elizabeth, 2017-06-11 16:45:52

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.
10abf66873a7468199be1d4e3093cca0.png
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="">

Here are my non-working functions
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;      
}

and screenshots of the database:
3791f7eaf72f448293d4d248a7138f59.pngf7c7f75c60364a998cce95851a5f2066.png
That is, I'm trying to ensure that the word is displayed like this:
d71eedbdcc7d4cb78e5912039d80e8bc.png
If anything, then for the output I go through the elements through
<?php $posts = det_posts(); ?>
<?php foreach($posts as $post): ?>
<?php endforeach; ?>

Please, help! I just started to figure it out and have been stuck on this for several hours :C

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Salim_Gareev, 2017-06-11
@elizaveta_kotik

Try to change

<div class="categor">
<?=$post['category']?>
</div>
<img src="<?=$post['image']?>" alt="">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question