j634 Posted July 8, 2009 Share Posted July 8, 2009 I have a form with a drop down menu and am calling an external language file. The language file works fine except when using the echo within this array. Does anyone have any options or suggestions? code <?PHP $maritalstatus = '<option value="<?php echo PARTNER126?>" /><?php echo PARTNER126?></option> <option value="<?php echo PARTNER14?>">Never Married</option> <option value="Divorced">Divorced</option> <option value="Widowed">Widowed</option> <option value="Separated">Separated</option> <option value="Annulled">Annulled</option>'; $maritalstatus = str_replace('<option value="'.$row['MaritalStatus'].'">', '<option value="'.$row['MaritalStatus'].'" selected>', $maritalstatus); echo $maritalstatus; ?> The PARTNER126 is for the language file. I need it to echo the value instead of writing in the value as above. As above it does not work. The normal values show fine, but no echo. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/165132-solved-echo-inside-an-array/ Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 What is the actual output? A blank screen, unexpected text, etc? Quote Link to comment https://forums.phpfreaks.com/topic/165132-solved-echo-inside-an-array/#findComment-870719 Share on other sites More sharing options...
j634 Posted July 8, 2009 Author Share Posted July 8, 2009 What is the actual output? A blank screen, unexpected text, etc? Where the php echo is at nothing is shown, only a blank space. Where the normal value is shown the output is normal. Quote Link to comment https://forums.phpfreaks.com/topic/165132-solved-echo-inside-an-array/#findComment-870722 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 Could you post your entire script... right now we can't see where the $row var is being specified. Quote Link to comment https://forums.phpfreaks.com/topic/165132-solved-echo-inside-an-array/#findComment-870726 Share on other sites More sharing options...
pmicro Posted July 8, 2009 Share Posted July 8, 2009 Looks like you've got <?php ... ?> nested inside of PHP code, that's not going to work. $maritalstatus = '<option value="<?php echo PARTNER126?>" /><?php echo PARTNER126?></option> <option value="<?php echo PARTNER14?>">Never Married</option> ... That code right there is going to make the value of the first option literally be <?php echo PARTNER126?>, which isn't what you want. You're going to want to set up some function to return the text from the language file. Like this: $maritalstatus = '<option value="' . get_language_text('PARTNER126') . '" />' . get_language_text('PARTNER126') . '</option> <option value="' . get_language_text('PARTNER14') . '">Never Married</option> ... function get_language_text($partner) { ... code to return text based on $partner param here ... return $text; } Quote Link to comment https://forums.phpfreaks.com/topic/165132-solved-echo-inside-an-array/#findComment-870738 Share on other sites More sharing options...
j634 Posted July 8, 2009 Author Share Posted July 8, 2009 Looks like you've got <?php ... ?> nested inside of PHP code, that's not going to work. $maritalstatus = '<option value="<?php echo PARTNER126?>" /><?php echo PARTNER126?></option> <option value="<?php echo PARTNER14?>">Never Married</option> ... That code right there is going to make the value of the first option literally be <?php echo PARTNER126?>, which isn't what you want. You're going to want to set up some function to return the text from the language file. Like this: $maritalstatus = '<option value="' . get_language_text('PARTNER126') . '" />' . get_language_text('PARTNER126') . '</option> <option value="' . get_language_text('PARTNER14') . '">Never Married</option> ... function get_language_text($partner) { ... code to return text based on $partner param here ... return $text; } Thanks for the tip and fast reply. I am still struggling with returning multiple values. It will display the PARTNER126 in both places, but it does output the correct word from the language file. I also tried to use an array, but it only output the word array in the drop down box. Any help on using the multiple call so that it will read each from the language file? <?PHP function get_language_text($partner) { $text = PARTNER126; $text = PARTNER14; return $text; } ?> The above will only output the first $text in both places. I tried to change the second $text to something like $text2 and return both values, but it did not work. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/165132-solved-echo-inside-an-array/#findComment-870805 Share on other sites More sharing options...
pmicro Posted July 8, 2009 Share Posted July 8, 2009 In your get_language_text($partner) function, you'll probably want to use a switch statement. That will allow you to see which partner value to use (based on $partner) then return the appropriate value, using the language constants you have Quote Link to comment https://forums.phpfreaks.com/topic/165132-solved-echo-inside-an-array/#findComment-871270 Share on other sites More sharing options...
j634 Posted July 9, 2009 Author Share Posted July 9, 2009 In your get_language_text($partner) function, you'll probably want to use a switch statement. That will allow you to see which partner value to use (based on $partner) then return the appropriate value, using the language constants you have Thanks again for your help, but I am still unable to get it working. This is the last code of my switch statement, after changing it about 50 times. Nothing will show in my drop down list using the switch statement. Could you post an example of how i am suppose to do it? I know I am close, but missing something. <?PHP function get_language_text($partner){ switch ($partner) { case "PARTNER126": case "PARTNER14": echo $partner; break; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/165132-solved-echo-inside-an-array/#findComment-871881 Share on other sites More sharing options...
j634 Posted July 9, 2009 Author Share Posted July 9, 2009 I have found a long way to do what I want. Which basically consists of a new function for each item. function get_language_text($partner){ $text = PARTNER126; return $text; } function get_language_text2($partner2){ $text = PARTNER14; return $text; } This does work. Quote Link to comment https://forums.phpfreaks.com/topic/165132-solved-echo-inside-an-array/#findComment-871889 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.