Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php empty result for language table

Tags:

arrays

php

mysql

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

enter image description here

And my PHP function is:

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

So also I used the following code for showing result but I am getting the empty result:

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

I know if I use $language['1'][$userLanguage]; then I get a result but I don't want to use id's here. Is there any way to do that to show results without using ids?

like image 668
Azzo Avatar asked Mar 05 '26 22:03

Azzo


1 Answers

You could 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 the data directly by its key:

echo $language['your_family'][$userLangauge];
like image 193
Mureinik Avatar answered Mar 08 '26 11:03

Mureinik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!