将单选/复选框更改为下拉框,对 PHP 编码进行最小的更改?

发布于 2024-10-20 07:20:29 字数 7978 浏览 3 评论 0原文

解决方案:感谢@Guarav 的建议,我受到了启发并最终提出了解决方案,请告诉我你们对我的解决方案的看法以及我可以进一步改进的任何方法。是的,这是一个挑战。我打赌你不能。

<?php 

function selectLang($a,$b,$c,$d,$e){

echo "<div id='menu2' style='width:250px; margin-left:-40px;'> <ul class='double'>

<li style='background:#333333; color:white;'>Demonstration Play Feature</li>";
echo "<form method='post'  action=''>";
echo "<li><select name='languages[]'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e)) {
echo "<option name='languages[]' value='$values1' />" . $list . "</option>";
echo "<option name='languages[]' value='$values1' />" . $list2 . "</option>";

}
echo "</select>";
echo "<input type='submit' value='Send' name='poll' /></li>";

echo "</form>";
echo "<li><b>" . $d ."</b>";
echo "<button onclick='JavaScript:changeSheets(1)' style='background-image:url(/misc/FYP/images/def.png); width:40px; height:40px; border:none;'></button>";
echo "<button onclick='JavaScript:changeSheets(2)' style='background-image:url(/misc/FYP/images/def1.png); width:40px; height:40px; border:none;'></button>";
echo "<button onclick='JavaScript:changeSheets(3)' style='background-image:url(/misc/FYP/images/def2.png); width:40px; height:40px; border:none;'></button>";
echo "<button onclick='JavaScript:changeSheets(4)' style='background-image:url(/misc/FYP/images/def3.png); width:40px; height:40px; border:none;'></button></li>";

echo "</ul></div>";
}

$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean","German");

$lang_eng1 = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_eng2 = array("French","Russian","Thai","Korean","German");

$lang_chi = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_chi2 = array("French","Russian","Thai","Korean","German");

$lang_jap = array("英語","日本語","中国語","ハンガリー語","アラビア語");
$lang_jap2 = array("フランス語","ロシア語","タイ語","韓国語","German");

$lang_rus = array("Английский","Японский","Китайский","Венгерский","Арабский");
$lang_rus2 = array("Французский","Русский","Тайский","Корейский","German");

$lang_kor = array("영어","일어","중국어","헝가리어","아라비아어");
$lang_kor2 = array("프랑스어","러시아어","타이어","한국어","German");

$lang_ger = array("Englisch","Japanisch","Chinesisch","Ungarisch","Arabisch",);
$lang_ger2 = array("Französisch","Russisch","Siamesisch","Koreanisch","German");

$h_eng = "Select Your Language";
$h_chi = "Select Your Language";
$h_jap = "言語の選択";
$h_rus = "Выбрать язык";
$h_kor = "언어 선택";
$h_ger = "Wählen Sie Ihre Sprache vor";

$h2_eng = "Change the Colour Scheme";
$h2_chi = "Change the Colour Scheme";
$h2_jap = "カラースキームの変更";
$h2_rus = "Изменить фон";
$h2_kor = "색채 설계";
$h2_ger = "Ändern Sie den Farbe Entwurf";

?>

在我的网站上,我有一个带有单选框的更改语言功能,如果单击其中一个,则网站的语言将会更改。这看起来像: 在此处输入图像描述

上面生成的代码是:

    <?php 

function selectLang($a,$b,$c,$d,$e,$f,$g){

echo "<div id='menu2' style='width:400px; margin-left:-40px;'> <ul class='triple'>

<li style='background:#333333; color:white; width:400px;'>Demonstration Play Feature</li>";
echo "<form method='post'  action=''>";
echo "<li style='width:400px;'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e) AND list(,$list3) = each($f) AND list(,$list4) = each($g)) {

echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list;
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list2;
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list3;
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list4 . "<br />";

}

echo "<input type='submit' value='Send' name='poll' /></li>";

echo "</form>";

echo "</ul></div>";
}

$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean","German");

$lang_eng1 = array("English","Japanese","Chinese","Hungarian");
$lang_eng2 = array("French","Russian","Arabic");
$lang_eng3 = array("Thai","Korean","German");
$lang_eng4 = array("Korean","German");
$lang_chi = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_chi2 = array("French","Russian","Thai","Korean","German");

$lang_jap = array("英語","日本語","中国語","ハンガリー語","アラビア語");
$lang_jap2 = array("フランス語","ロシア語","タイ語","韓国語","German");

$lang_rus = array("Английский","Японский","Китайский","Венгерский","Арабский");
$lang_rus2 = array("Французский","Русский","Тайский","Корейский","German");

$lang_kor = array("영어","일어","중국어","헝가리어","아라비아어");
$lang_kor2 = array("프랑스어","러시아어","타이어","한국어","German");

$lang_ger = array("Englisch","Japanisch","Chinesisch","Ungarisch","Arabisch",);
$lang_ger2 = array("Französisch","Russisch","Siamesisch","Koreanisch","German");

$h_eng = "Select Your Language";
$h_chi = "Select Your Language";
$h_jap = "言語の選択";
$h_rus = "Выбрать язык";
$h_kor = "언어 선택";
$h_ger = "Wählen Sie Ihre Sprache vor";


?>

但是,我不再需要单选/复选框。无论如何,我可以将其更改为下拉框,它仍然可以完全相同地工作吗?

感谢您的任何建议。

**编辑: @高拉夫 我尝试了您的建议,最终代码如下:

   <?php 

function selectLang($a,$b,$c,$d,$e){

echo "<div id='menu2' style='width:250px; margin-left:-40px;'> <ul class='double'>

<li style='background:#333333; color:white;'>Demonstration Play Feature</li>";
echo "<form method='post'  action=''>";
echo "<li>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e)) {

echo "<input type='radio' name='languages[]' value='$values1' />" . $list;
echo "<input type='radio' name='languages[]' value='$values1' />" . $list2 . "<br />";
}
***echo "<li>";
echo "<select name='languages[]'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e) AND list(,$list3) = each($f) AND list(,$list4) = each($g)) {

echo "<option value='$values1'>" . $list ."</option>";
echo "<option value='$values1'>" . $list ."</option>";
echo "<option value='$values1'>" . $list ."</option>";

}
echo "</select>";
echo "</li>";***

echo "<input type='submit' value='Send' name='poll' /></li>";


echo "</form>";


echo "</ul></div>";
}

$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean","German");

$lang_eng1 = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_eng2 = array("French","Russian","Thai","Korean","German");

$lang_chi = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_chi2 = array("French","Russian","Thai","Korean","German");

$lang_jap = array("英語","日本語","中国語","ハンガリー語","アラビア語");
$lang_jap2 = array("フランス語","ロシア語","タイ語","韓国語","German");

$lang_rus = array("Английский","Японский","Китайский","Венгерский","Арабский");
$lang_rus2 = array("Французский","Русский","Тайский","Корейский","German");

$lang_kor = array("영어","일어","중국어","헝가리어","아라비아어");
$lang_kor2 = array("프랑스어","러시아어","타이어","한국어","German");

$lang_ger = array("Englisch","Japanisch","Chinesisch","Ungarisch","Arabisch",);
$lang_ger2 = array("Französisch","Russisch","Siamesisch","Koreanisch","German");

$h_eng = "Select Your Language";
$h_chi = "Select Your Language";
$h_jap = "言語の選択";
$h_rus = "Выбрать язык";
$h_kor = "언어 선택";
$h_ger = "Wählen Sie Ihre Sprache vor";

$h2_eng = "Change the Colour Scheme";
$h2_chi = "Change the Colour Scheme";
$h2_jap = "カラースキームの変更";
$h2_rus = "Изменить фон";
$h2_kor = "색채 설계";
$h2_ger = "Ändern Sie den Farbe Entwurf";


?>

但它只显示了一个下拉框,下拉框中没有任何值。但这是一个开始,谢谢。关于如何进一步发展这个的任何想法?**

Solution: thanks to the suggestion from @Guarav I was inspired and FINALLY came up with the solution, please tell me what you guys think of my solution and any ways I can improve this further. And yes, thats a challenge. Bet you can't.

<?php 

function selectLang($a,$b,$c,$d,$e){

echo "<div id='menu2' style='width:250px; margin-left:-40px;'> <ul class='double'>

<li style='background:#333333; color:white;'>Demonstration Play Feature</li>";
echo "<form method='post'  action=''>";
echo "<li><select name='languages[]'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e)) {
echo "<option name='languages[]' value='$values1' />" . $list . "</option>";
echo "<option name='languages[]' value='$values1' />" . $list2 . "</option>";

}
echo "</select>";
echo "<input type='submit' value='Send' name='poll' /></li>";

echo "</form>";
echo "<li><b>" . $d ."</b>";
echo "<button onclick='JavaScript:changeSheets(1)' style='background-image:url(/misc/FYP/images/def.png); width:40px; height:40px; border:none;'></button>";
echo "<button onclick='JavaScript:changeSheets(2)' style='background-image:url(/misc/FYP/images/def1.png); width:40px; height:40px; border:none;'></button>";
echo "<button onclick='JavaScript:changeSheets(3)' style='background-image:url(/misc/FYP/images/def2.png); width:40px; height:40px; border:none;'></button>";
echo "<button onclick='JavaScript:changeSheets(4)' style='background-image:url(/misc/FYP/images/def3.png); width:40px; height:40px; border:none;'></button></li>";

echo "</ul></div>";
}

$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean","German");

$lang_eng1 = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_eng2 = array("French","Russian","Thai","Korean","German");

$lang_chi = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_chi2 = array("French","Russian","Thai","Korean","German");

$lang_jap = array("英語","日本語","中国語","ハンガリー語","アラビア語");
$lang_jap2 = array("フランス語","ロシア語","タイ語","韓国語","German");

$lang_rus = array("Английский","Японский","Китайский","Венгерский","Арабский");
$lang_rus2 = array("Французский","Русский","Тайский","Корейский","German");

$lang_kor = array("영어","일어","중국어","헝가리어","아라비아어");
$lang_kor2 = array("프랑스어","러시아어","타이어","한국어","German");

$lang_ger = array("Englisch","Japanisch","Chinesisch","Ungarisch","Arabisch",);
$lang_ger2 = array("Französisch","Russisch","Siamesisch","Koreanisch","German");

$h_eng = "Select Your Language";
$h_chi = "Select Your Language";
$h_jap = "言語の選択";
$h_rus = "Выбрать язык";
$h_kor = "언어 선택";
$h_ger = "Wählen Sie Ihre Sprache vor";

$h2_eng = "Change the Colour Scheme";
$h2_chi = "Change the Colour Scheme";
$h2_jap = "カラースキームの変更";
$h2_rus = "Изменить фон";
$h2_kor = "색채 설계";
$h2_ger = "Ändern Sie den Farbe Entwurf";

?>

On my website I have a change language feature with radio boxes, if one is clicked then the language of the website will change. This looks like:
enter image description here

The code for what is produced above is:

    <?php 

function selectLang($a,$b,$c,$d,$e,$f,$g){

echo "<div id='menu2' style='width:400px; margin-left:-40px;'> <ul class='triple'>

<li style='background:#333333; color:white; width:400px;'>Demonstration Play Feature</li>";
echo "<form method='post'  action=''>";
echo "<li style='width:400px;'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e) AND list(,$list3) = each($f) AND list(,$list4) = each($g)) {

echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list;
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list2;
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list3;
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list4 . "<br />";

}

echo "<input type='submit' value='Send' name='poll' /></li>";

echo "</form>";

echo "</ul></div>";
}

$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean","German");

$lang_eng1 = array("English","Japanese","Chinese","Hungarian");
$lang_eng2 = array("French","Russian","Arabic");
$lang_eng3 = array("Thai","Korean","German");
$lang_eng4 = array("Korean","German");
$lang_chi = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_chi2 = array("French","Russian","Thai","Korean","German");

$lang_jap = array("英語","日本語","中国語","ハンガリー語","アラビア語");
$lang_jap2 = array("フランス語","ロシア語","タイ語","韓国語","German");

$lang_rus = array("Английский","Японский","Китайский","Венгерский","Арабский");
$lang_rus2 = array("Французский","Русский","Тайский","Корейский","German");

$lang_kor = array("영어","일어","중국어","헝가리어","아라비아어");
$lang_kor2 = array("프랑스어","러시아어","타이어","한국어","German");

$lang_ger = array("Englisch","Japanisch","Chinesisch","Ungarisch","Arabisch",);
$lang_ger2 = array("Französisch","Russisch","Siamesisch","Koreanisch","German");

$h_eng = "Select Your Language";
$h_chi = "Select Your Language";
$h_jap = "言語の選択";
$h_rus = "Выбрать язык";
$h_kor = "언어 선택";
$h_ger = "Wählen Sie Ihre Sprache vor";


?>

However, I dont want the radio/check boxes anymore. Is there anyway i can change this to a drop down box which will still work exactly the same?

thank you for any suggestions.

**Edit:
@Gaurav
I tried you suggestion with the final code which looked like:

   <?php 

function selectLang($a,$b,$c,$d,$e){

echo "<div id='menu2' style='width:250px; margin-left:-40px;'> <ul class='double'>

<li style='background:#333333; color:white;'>Demonstration Play Feature</li>";
echo "<form method='post'  action=''>";
echo "<li>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e)) {

echo "<input type='radio' name='languages[]' value='$values1' />" . $list;
echo "<input type='radio' name='languages[]' value='$values1' />" . $list2 . "<br />";
}
***echo "<li>";
echo "<select name='languages[]'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e) AND list(,$list3) = each($f) AND list(,$list4) = each($g)) {

echo "<option value='$values1'>" . $list ."</option>";
echo "<option value='$values1'>" . $list ."</option>";
echo "<option value='$values1'>" . $list ."</option>";

}
echo "</select>";
echo "</li>";***

echo "<input type='submit' value='Send' name='poll' /></li>";


echo "</form>";


echo "</ul></div>";
}

$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean","German");

$lang_eng1 = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_eng2 = array("French","Russian","Thai","Korean","German");

$lang_chi = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_chi2 = array("French","Russian","Thai","Korean","German");

$lang_jap = array("英語","日本語","中国語","ハンガリー語","アラビア語");
$lang_jap2 = array("フランス語","ロシア語","タイ語","韓国語","German");

$lang_rus = array("Английский","Японский","Китайский","Венгерский","Арабский");
$lang_rus2 = array("Французский","Русский","Тайский","Корейский","German");

$lang_kor = array("영어","일어","중국어","헝가리어","아라비아어");
$lang_kor2 = array("프랑스어","러시아어","타이어","한국어","German");

$lang_ger = array("Englisch","Japanisch","Chinesisch","Ungarisch","Arabisch",);
$lang_ger2 = array("Französisch","Russisch","Siamesisch","Koreanisch","German");

$h_eng = "Select Your Language";
$h_chi = "Select Your Language";
$h_jap = "言語の選択";
$h_rus = "Выбрать язык";
$h_kor = "언어 선택";
$h_ger = "Wählen Sie Ihre Sprache vor";

$h2_eng = "Change the Colour Scheme";
$h2_chi = "Change the Colour Scheme";
$h2_jap = "カラースキームの変更";
$h2_rus = "Изменить фон";
$h2_kor = "색채 설계";
$h2_ger = "Ändern Sie den Farbe Entwurf";


?>

But it only showed a drop down box, it didnt have any values in the drop box. But its a start thanks. any ideas on how we can develop this further?**

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只为一人 2024-10-27 07:20:29

在函数中使用此代码并让我知道它是否有效。

echo "<select name='languages[]'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e) AND list(,$list3) = each($f) AND list(,$list4) = each($g)) {

echo "<option value='$values1'>" . $list ."</option>";  // change value and text ($list) according to you
echo "<option value='$values1'>" . $list ."</option>";
}
echo "</select>";

use this code in function and let me know it works or not.

echo "<select name='languages[]'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e) AND list(,$list3) = each($f) AND list(,$list4) = each($g)) {

echo "<option value='$values1'>" . $list ."</option>";  // change value and text ($list) according to you
echo "<option value='$values1'>" . $list ."</option>";
}
echo "</select>";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文