www.webdeveloper.com
Results 1 to 4 of 4

Thread: Select Database Table Row Function

  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Select Database Table Row Function

    PHP Code:
        function selectLanguage($c)
        {
            global 
    $l// Get language code from url via $_GET method
            
            
    if (($l) AND (($l == 'en') OR ($l == 'de')))
            {
                if (
    $l == 'en')
                {
                    return 
    $c;
                }
                if (
    $l == 'de')
                {
                    return 
    $c.'_l1';
                }
            }
            else
            {
            return 
    $c;
            }    
        } 
    I have a sql table. It's name is content.
    In content table, i have 2 rows. These are content_main and content_main_l1.

    The rows are have same content. content_main is in english. content_main_l1 is in german.

    My links are like;

    xxx.com/en/content
    xxx.com/de/content

    I want, if url contains en, the function returns content_main and if url contains de the function return content_main_l1.


    PHP Code:
    echo selectLanguage($content->content_main);  // I use ezsql class so i write row name like $content->content main 
    I use the function like above. But the output is like;
    $content->content_main_l1 or $content->content_main

    OR

    if i use quote or double quote the output is like;

    contentOfRow_lr or contentOfRow

    So how can i run this function correct.

  2. #2
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    In my experience this is passed as part of the request headers ($_GET):

    http://yourURL.ext/pages/page.php?lang=en

    PHP Code:
    if(isset($_GET['lang'])) 
      switch(
    $_GET['lang']):
        case(
    'en'): 
          echo 
    selectLanguage($content->content_main);
          break;
        case(
    'de'): 
          echo 
    selectLanguage($content->content_main_l1);; break;
        default:    
          echo 
    selectLanguage($content->content_main);
          break;
       endswitch;

    #or 

    echo (isset($_GET['lang']) && $_GET['lang'] == 'de') ? 
      
    $content->content_main_l1 
      
    $content->content_main
    Cheers

  3. #3
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    I would do it like this (if you dont like the GET method):
    PHP Code:
    $lang explode('/',$_SERVER['PATH_INFO']);
    if(
    $lang[1] == 'en'){
          echo 
    selectLanguage($content->content_main);
    }elseif(
    $lang[1] == 'de'){
          echo 
    selectLanguage($content->content_main_l1);
    }else{
          echo 
    'Invalid Language';


  4. #4
    Join Date
    Feb 2012
    Posts
    2
    These are not solution of my problem. Because content->content_main is just a sample. I have lots of tables and rows. So i'm trying to write a function.


    anyway...

    I found the solution.
    PHP Code:
    function selectLanguage($c)
    {
        global 
    $l;

        if ((
    $l) AND (($l == 'tr') OR ($l == 'en')))
        {
            if (
    $l == 'tr')
            {
                return 
    $c;
            }
            if (
    $l == 'en')
            {
                return ${
    $c.'_l1'};
            }
        }
        else
        {
        return 
    $c;
        }    


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles