PHP - execute certain code depending on ?lang=

pcwacht

Cleaned it up a bit for clarity and readablitity


<?php
if (LANGUAGE==SE) { 
    
$section_id 10;   //change this section_id for Your needings
} elseif (LANGUAGE==EN) {
    
$section_id 11//change this section_id for Your needings
} else {
    
$section_id 12//change this section_id for Your needings
}
if (isset(
$section_id)) { // Maker sure section isset
    
$query_sec $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");
    if(
$query_sec->numRows() > 0) {
        
$section $query_sec->fetchRow();
        
$section_id $section['section_id'];
        
$module $section['module'];
        require(
WB_PATH.'/modules/'.$module.'/view.php'); //statt view.php die alternative eintragen!
    
}
}
<?


Have fun,
John

[url="http://www.ictwacht.nl"]http://www.ictwacht.nl[/url] = Dutch ICT info
[url="http://www.pcwacht.nl"]http://www.pcwacht.nl[/url] = My first
both still work in progress, since years.....

Lotus

Quote from: vyni on December 15, 2008, 06:06:35 PM
maybe it is does what Your are looking for.

regards from Himberg, near Vienna


This code is so great I can´t believe my eyes  :-D, thanx Himberg! This opens up lots of possibilities when making templates, until now i solved all this issues with another template, but always thought it was "not quite right" doing so.

Regards Sweden!

vyni

Hi Lotus,

try this code


<?php
if (LANGUAGE==SE) {
$section_id 10//change this section_id for Your needings
$query_sec $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");
if(
$query_sec->numRows() > 0) {
$section $query_sec->fetchRow();
$section_id $section['section_id'];
$module $section['module'];
require(
WB_PATH.'/modules/'.$module.'/view.php'); //statt view.php die alternative eintragen!
}
} else  if (
LANGUAGE==EN) {
$section_id 11//change this section_id for Your needings
$query_sec $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");
if(
$query_sec->numRows() > 0) {
$section $query_sec->fetchRow();
$section_id $section['section_id'];
$module $section['module'];
require(
WB_PATH.'/modules/'.$module.'/view.php'); //statt view.php die alternative eintragen!
}
} else {
$section_id 12//change this section_id for Your needings
$query_sec $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");
if(
$query_sec->numRows() > 0) {
$section $query_sec->fetchRow();
$section_id $section['section_id'];
$module $section['module'];
require(
WB_PATH.'/modules/'.$module.'/view.php'); //statt view.php die alternative eintragen!
}
}
<?


maybe it is does what Your are looking for.

regards from Himberg, near Vienna

Lotus

That is great news, just dont know how to acually write the code. Believe me i would have if i knew. :-D

kweitzel

You can just query the language directly, you don't need to go via the "Request_URI" ...

Have a look here: http://help.websitebaker.org/pages/en/advanced-docu/developer-guide/variables-and-constants.php

cheers

Klaus

Lotus

Hello, need som PHP-help with my template.php im trying to do multinlingual. I have two sections that i want to be global. But I want them to show depending on ?lang= set.

If lang=se
show section 10
else if lang=en
show section 11
else
show section 12

I have this code but out of ideas  :-D, anyone up to it?


        <?php
        $url 
$_SERVER['REQUEST_URI'];
          if (strrpos($url,"hem.php"))  {
        
?>

            <img  src="<?php echo TEMPLATE_DIR?>/images/imagebild2.gif"  />
        <?php    
        } elseif (strrpos($url,"home.php")) {
         ?>

       <img  src="<?php echo TEMPLATE_DIR?>/images/imagebild2.gif"  />
        <?php
          
} else {
        
?>

       <img  src="<?php echo TEMPLATE_DIR?>/images/imagebild.gif"  />
   <?php ?>

       

        <?php
        $section_id 
9;             
        $query_sections 
$database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");
        if($query_sections->numRows() > 0) {
            $section $query_sections->fetchRow();
            $section_id $section['section_id'];
            $module $section['module'];
            require(WB_PATH.'/modules/'.$module.'/view.php');
        
        ?>