Reply
include & function problem
Old 05-09-2007, 04:40 AM include & function problem
Junior Talker

Posts: 2
HI all, i hope that you wil lassist me with this problem.

The general idea is to have all language variables in one file per language and to display them where it is needed.
Now, i have the following:

In page index.php
PHP Code:
// database connection, setting the $lang etc...

    
include ("inc/dictionary_$lang.php");
    include_once (
"inc/function.php");

// fetch info from db
    
$strana "SELECT id AS page_id, strana_$lang AS naslov, template_id FROM strane WHERE id='$page_id'";
    
$result mysql_query($strana);    
    
$myrow mysql_fetch_array($result);
    
$page_id=$myrow["page_id"];
    
$naslov=$myrow["naslov"];
    
$template=$myrow["template_id"];

// Insert head and top of the page
        
include ("inc/top.html");

// Insert main part of page
        
include ("templates/template$template.htm");

// something 
in dictionary_$lang.php
i have the following
PHP Code:
$f_name "Name";
$f_lastname "Last name";
// and so on... 
html template looks like this:

HTML Code:
...
                <tr>
                 <td width="210"><? echo $f_lastname?> * </td>
                 <td width="290"><input name="lastname" type="text" id="lastname" /></td>
                </tr>
                <tr>
                 <td><? echo $f_name?>* </td>
                 <td><input name="name" type="text" id="name" /></td>
                </tr>
...
this is from function.php
PHP Code:
function print_fields ()
{
    switch (
$form
        {
            case 
1:
            
// array to describe fields
            
$mail_1 = array($f_lastname$f_name'adress''plz');
            
// array to print values
            
$mail_2 = array($_POST['lastname'], $_POST['name'], $_POST['adress'], $_POST['plz'];
            break; 

if (
$mail_2)
    {
    
// print description and values
    
echo '<table border=1 width=500>';
    for(
$i=0$i<=count($mail_1)-1$i++)
        {
        echo 
'<tr>';
        echo 
' <td width=150>'.$mail_1[$i].': </td>';
        echo 
' <td>'.$mail_2[$i].'</td>';
        echo 
'<tr>';
        }
    echo 
'</table>';
    }
    else
    {
        echo 
" error";
    }

This doesn't work, since function doesn't recognize variables from dictionary file.
If i change fucntion to this
PHP Code:
function print_fields  ()
{
    GLOBAL 
$lang;
    include (
"inc/dictionary_$lang.php");
// etc 
it works, but i don't see it as nice solution... any suggestions?
AleksBG is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-09-2007, 07:39 AM Re: include & function problem
Ultra Talker

Posts: 479
I would say that it's not so much that your variables aren't recognised but that you would have to state (for each and every variable) that they are global variables (as you did with $lang) before accessing them.

If it were me, instead of setting each language string as a separate variable, I would make them items in an array. Then, in the print_fields function I would just have to have 'global $language_array;' and I could then accessing all of the language strings.

Hopefully that makes sense.
__________________
Free PHP Obfuscator
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 05-09-2007, 07:59 AM Re: include & function problem
Skilled Talker

Posts: 60
Name: bilton
i agree withtwist arm
niceguy_81333 is offline
Reply With Quote
View Public Profile
 
Old 05-09-2007, 08:19 AM Re: include & function problem
Junior Talker

Posts: 2
Thanks for your comment.
Can you tell me how would i be able to change values printed on the screen which are described in print_fields () function ?
As i see it, i am back on the same problem - how can variables from the array print different results according to selected language?

AleksBG is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to include & function problem
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13219 seconds with 13 queries