PHP语言和数据库

is a long question but I hope you can help me

Well I have added a system to switch language on my site but now I want to make the language file dynamyc...

I will try to explain everything so:

I have this file to create a slide on my home page:

<?PHP

$sql = "SELECT img_url, caption  FROM cc_homeslide  ORDER BY position asc";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "<div><figure><div class='dark-effect'><img class='lazyOwl' data-src='images/slide_home/fake_img.png' alt='Awesone Food' style='background-image: url(images/slide_home/". $row["img_url"]. ")' /></div><figcaption>". $row["caption"] ."</figcaption></figure></div>";
    }
} else {
    echo "0 results";
}

?>

Perfect is working. But now I want to switch $row["caption"] to $lang["SLIDE_CAPTION"]

Why? Because in my file en.php I have this:

<?php
/*
------------------
Language: English
------------------
*/

$lang = array();

 //HEAD

$lang['PAGE_TITLE'] = 'Food Delivery from quality restaurants in Hong Kong';
$lang['PAGE_DESCRIPTION'] = 'Order Food from your favorite restaurant and delivers them to your home or office ● Pay Online or Cash On Delivery';
$lang['PAGE_KEYWORDS'] = 'order food online, food delivery in Hong Kong, quality restaurants delivery';

// MENU

$lang['LANG'] = 'Eng';
$lang['LOC_HK'] = 'Hong Kong';
$lang['LOC_KW'] = 'Kowloon';

//SLIDE
require_once ("connect.php");

$sql = "SELECT img_url, caption  FROM cc_homeslide  ORDER BY position asc";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $lang['SLIDE_CAPTION'] = $row["caption"];
    }
}

?>

but the problem is that I can not make the caption match with the right row on the database. With this code I am getting the same caption for all the rows on the database...

So I need to make $lang['SLIDE_CAPTION'] = "caption on each row"

Any idea?

I have tried to explain in the best way but if you are interested and can not understand let me know and I am going to explain again

Each key in an array must be unique. Your loop generating $lang['SLIDE_CAPTION'] = $row["caption"]; is returning each row value into the same variable - so $lang['SLIDE_CAPTION'] will only ever be the last value from your loop.

Build a $slideCaptions array to hold all captions, using a unique field from the database table as the key:

$slideCaptions = array();

while($row = mysqli_fetch_assoc($result)) {
    $slideCaptions[$row["id"]] = $row["caption"];
}

Then, access the caption in your array using the key to output value:

while($row = mysqli_fetch_assoc($result)) {
    echo "<div>...</div>
          <figcaption>". $slideCaptions[$row["id"]] ."</figcaption></div>";
}