CodeIgniter Forums
Database Query Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Database Query Problem (/showthread.php?tid=8066)



Database Query Problem - El Forum - 05-04-2008

[eluser]Gewa[/eluser]
Hi I have in my database fields 'id','alias', 'de', 'en', 'ru' for category section.


So using URI Language Identifier, i get the current language, and now I want to get the right data and display them so i make


Code:
$query = $this->db->query("SELECT `$lang` FROM `cats` ");

foreach ($query->result_array() as $row)
{
   echo $row[$lang];
  
}


But its not working. Which is the best way, when you have lets say more than 1 listings and you should display them depending on $lang ?


Database Query Problem - El Forum - 05-04-2008

[eluser]gtech[/eluser]
i tried your query and it only worked when I took the single quotes out

$query = $this->db->query("SELECT $lang FROM cats");

hope it helps.

here is my code (my datbase table is of course different to yours)
Code:
<?php
class Home extends Controller   {
  function Home(){
    parent::Controller();
  }

  function links() {
    $lang = 'name';
    $query = $this->db->query("SELECT $lang FROM users ");
    foreach ($query->result_array() as $row)
    {
      echo $row[$lang]."<br>";
    }
  }
}
?&gt;



Database Query Problem - El Forum - 05-04-2008

[eluser]Gewa[/eluser]
Thank you very much. WIll try now your code, hope it will help