PDA

View Full Version : Guru needed to solve this


scsi
01-14-2003, 10:54 AM
I'm setting up a multilingual site using phpLang.
It works fine for all site but not in this case..
site is structured with a db, but many options reside on flat files.

I must find a way to have those files multilingual.
actually I've this:

<?
$options = file("orientation.php");
$num_options = count($options);


print "<select size='1' name='orientation'>";
print "<option value='$orientation' selected>$orientation";
for ($i=0; $i<$num_options; $i++)
{
print "<option value='$options[$i]' ";

if (trim($orientation)== trim($options[$i]))
{
print "selected";
}

print ">$options[$i]</option>";
}
print "</select>";
?>

-- this select box fetch options contained in orientation.php

-------
content of orientation.php (called by select box):

<? echo (A) ?> ---- no works
(B) ---- no works
right

only third option works but it's no multilingual!!
-----

content of orientation.php (under language):
<?php
define("A", "right");
define("B", "left");
?>

I will be gratefull for your help

scsi
01-14-2003, 01:57 PM
Giving more specification....
Now,

<?
$options = file("orientation.php");
$num_options = count($options);
print "<select size='1' name='orientation'>";
print "<option value='$orientation' selected>$orientation";
print " <option value='%'>------";
for ($i=0; $i<$num_options; $i++)
{
print "<option value='$options[$i]' ";

if (trim($orientation)== trim($options[$i]))
{
print "selected";
}

print ">$options[$i]</option>";
}
print "</select>";
?>

is giving this output:

<select size='1' name='orientation'><option value='' selected> <option

value='%'>---<option value='right' >right
</option><option value='left' >left</option></select>

but output needed is:

<select size='1' name='orientation'><option value='' selected> <option

value='%'>---<option value='<? echo (A) ?>' ><? echo (A) ?>
</option><option value='<? echo (B) ?>' ><? echo (B) ?></option></select>

mordred
01-14-2003, 04:06 PM
No understand.

Why do you want the output to be "<? echo A ?>"? I'd rather think you wanted the value of the constants printed. On the other hand, I'm no guru, so maybe that's why I don't understand your request.

scsi
01-14-2003, 04:11 PM
ok,
can you tell me how you would do to have the value of the constants printed?
thank

mordred
01-14-2003, 04:13 PM
echo A;
echo B;

scsi
01-14-2003, 05:55 PM
doesn't work

mordred
01-14-2003, 07:23 PM
What a precise error description!

It works the way I described:


define('A', 'test for A');
define('B', ', test for B');

echo A;
echo B;


At least with PHP4.3 and it happily prints 'test for A, test for B'. Perhaps your problem is with file() - if you have the constants defined in another PHP script, just include() it, and they become available to your script.

scsi
01-14-2003, 08:26 PM
ok, try to ask in this way:

user table has a field named color.
options are red - white - black.
I've a template file where are defined

define('A', 'red');
define('B', ', white');
define('C', 'black');

now have user with color red...

<?
$result = mysql_query("select * from user ");
$row = mysql_fetch_array($result);
$color = $row[color];

print "$color";?>

it output me A instead of red

so the question is where is the error? in value inserted in mysql (A) or in php?

mordred
01-14-2003, 09:02 PM
...so you want to echo the value of a constant, and the value in the database should define which constant it is?

Try this:


$constantsArray = get_defined_constants();
echo $constantsArray[$color];


but that's really awkward... why don't you store the color info directly in an array or an object instead? Constants are normally used in a slightly different context.

scsi
01-14-2003, 09:05 PM
please take a look at your private messagges