Php zend practice - help me solve this
06-04-2010, 03:24 AM
|
Php zend practice - help me solve this
|
Posts: 6
Name: Ryan Murphy
|
I am currently studying for my qualification in becoming a Zend PHP programmer. And we were given this broken script to fix, can you help me fix this?
Code:
<?php
$lang_eng = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean");
$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean");
$header = "Select Your Language";
function selectLang($header,$lang_eng,$values){
echo $header;
echo "<br />";
echo "<form method='post' style='margin-left:-5px; margin-bottom:5px;' action=''>";
foreach($lang_eng as $list){
foreach ($values as $values1){
echo "<label>";
echo "<input type='radio' name='languages[]' value='$values1' />" . $list;
echo "</label>";};};
echo "<br /><br />";
echo "<input type='submit' value='Send' name='poll' />";
echo "</form>";
echo "Change the Colour Scheme<br>";
echo "<button onclick='JavaScript:changeSheets(1)' class='button'></button>";
echo "<button onclick='JavaScript:changeSheets(2)' class='button1'></button>";
echo "<button onclick='JavaScript:changeSheets(3)' class='button2'></button>";
echo "<button onclick='JavaScript:changeSheets(4)' class='button3'></button>";
echo "</div>";
};
echo selectLang($header,$lang_eng,$values);
This codes output is odd to say the least.
All suggestions, improvements and fixes are welcome.
|
|
|
|
06-04-2010, 04:32 AM
|
Re: Php zend practice - help me solve this
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
How exactly is it broken? There were no error messages when I ran it. What is it supposed to do that it isn't doing or isn't doing correctly?
|
|
|
|
06-04-2010, 04:53 AM
|
Re: Php zend practice - help me solve this
|
Posts: 6
Name: Ryan Murphy
|
When the script is run, no errors are generated, thats why fixing this has been said to be a little tricky for sum.
As you notice , when run, several of each language appears with a checkbox next to them, what needs to happen is have only one of every country?
I hope I made sense, do you understand what i was trying to say?
|
|
|
|
06-04-2010, 05:12 AM
|
Re: Php zend practice - help me solve this
|
Posts: 6
Name: Ryan Murphy
|
I have been working on it and tried this but no luck so far, for some reason when i run this code, instead of showing several of each language in the variable array $lang_eng, it only outputs 'Korean'. any suggestions?
Code:
<?php
$lang_eng = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean");
$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean");
$header = "Select Your Language";
function selectLang($a,$b,$c){
$html = $a;
$html .= "<br />";
$html .= "<form method='post' style='margin-left:-5px; margin-bottom:5px;' action=''>";
foreach($b as $list){
}
foreach ($c as $values1){
}
$html .= "<label>";
$html .= "<input type='radio' name='languages[]' value='$values1' />" . $list;
$html .= "</label>";
$html .= "<br /><br />";
$html .= "<input type='submit' value='Send' name='poll' />";
$html .= "</form>";
$html .= "Change the Colour Scheme<br>";
$html .= "<button onclick='JavaScript:changeSheets(1)' class='button'></button>";
$html .= "<button onclick='JavaScript:changeSheets(2)' class='button1'></button>";
$html .= "<button onclick='JavaScript:changeSheets(3)' class='button2'></button>";
$html .= "<button onclick='JavaScript:changeSheets(4)' class='button3'></button>";
$html .= "</div>";
return $html;
};
$output = selectLang($header,$lang_eng,$values);
echo $output;
|
|
|
|
06-04-2010, 06:37 AM
|
Re: Php zend practice - help me solve this
|
Posts: 6
Name: Ryan Murphy
|
I have had a bit of progress further, i can get the right amount of checkboxes to turn up, working correctly but no text appears along side them.
Any suggestions?
Code:
$lang_eng = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean");
$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean");
$header = "Select Your Language";
function selectLang($header,$lang_eng,$values){
echo $header;
echo "<br />";
echo "<form method='post' style='margin-left:-5px; margin-bottom:5px;' action=''>";
while(list(,$list) = each($lang_eng) && list(,$values1) = each($values)) {
echo "<label>";
echo "<input type='radio' name='languages[]' value='$values1' />" . $list;
echo "</label>";}
echo "<br /><br />";
echo "<input type='submit' value='Send' name='poll' />";
echo "</form>";
echo "Change the Colour Scheme<br>";
echo "<button onclick='JavaScript:changeSheets(1)' class='button'></button>";
echo "<button onclick='JavaScript:changeSheets(2)' class='button1'></button>";
echo "<button onclick='JavaScript:changeSheets(3)' class='button2'></button>";
echo "<button onclick='JavaScript:changeSheets(4)' class='button3'></button>";
echo "</div>";
};
echo selectLang($header,$lang_eng,$values)
|
|
|
|
06-04-2010, 06:41 AM
|
Re: Php zend practice - help me solve this
|
Posts: 6
Name: Ryan Murphy
|
SOLVED
Switched the foreach with a while
Can anyone tell me why the foreach wouldnt work with 2 arrays?
Code:
<?php
$lang_eng = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean");
$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean");
$header = "Select Your Language";
function selectLang($header,$lang_eng,$values){
echo $header;
echo "<br />";
echo "<form method='post' style='margin-left:-5px; margin-bottom:5px;' action=''>";
while(list(,$values1) = each($values) AND list(,$list) = each($lang_eng)) {
echo "<label>";
echo "<input type='radio' name='languages[]' value='$values1' />" . $list;
echo "</label>";}
echo "<br /><br />";
echo "<input type='submit' value='Send' name='poll' />";
echo "</form>";
echo "Change the Colour Scheme<br>";
echo "<button onclick='JavaScript:changeSheets(1)' class='button'></button>";
echo "<button onclick='JavaScript:changeSheets(2)' class='button1'></button>";
echo "<button onclick='JavaScript:changeSheets(3)' class='button2'></button>";
echo "<button onclick='JavaScript:changeSheets(4)' class='button3'></button>";
echo "</div>";
}
?>
|
|
|
|
06-12-2010, 07:57 PM
|
Re: Php zend practice - help me solve this
|
Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
|
Thanks for updating us with your solution, Ryan. Best wishes on your testing.
__________________
Jeremy Miller
Please login or register to view this content. Registration is FREE
|
|
|
|
|
« Reply to Php zend practice - help me solve this
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|