Php empty result for language table

I am trying to add multiple language options to the database. I created a table as follows.

enter image description here

And my PHP function:

    public function Languages(){
SELECT  * FROM languages") or die(mysqli_error($this->db)); 
                while($row=mysqli_fetch_array($query,MYSQLI_ASSOC)) {
             if(!empty($data)) {
                // Store the result into array
                return $data;


So, I used the following code to show the result, but I get an empty result:

  $language = $ReSult->Languages();
   $userLanguage = 'english';
   echo  $language['your_family'][$userLangauge];


I know if I use $language['1'][$userLanguage];

, then I get the result, but I don't want to use id here. Is there a way to do this in order to show results without using IDs?


source to share

3 answers

You can store the results in an associative array:

while ($row = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
    $data[$row['lang_key']] = $row;


This way you can access data directly using your key:

echo $language['your_family'][$userLangauge];




check it out

function getIndex($language  , $key)
  foreach ($language as $row) 
    if (strcmp($row["lang_key"] , $key)==0) {
      return $row["id"]
  return null;


echo $language[getIndex($language , "your_family")][$userLanguage];




You can try this way

while ($row = mysqli_fetch_assoc($query)) {
    $data[$row['tagKey']] = $row;




All Articles