Jump to content

mckenzie

Members
  • Posts

    54
  • Joined

  • Last visited

mckenzie's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I've reduced the number of functions and cleaned it up a bit. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>BBK ITApps - Web Programming using PHP</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <?php //,'./hoe7b_data/visibility.txt','./hoe7b_data/weather.txt' $files = array('./hoe7b_data/temperature.txt','./hoe7b_data/visibility.txt','./hoe7b_data/weather.txt'); $week = array( "Mon" => array( 'temp' => NULL, 'visi' => NULL, 'weat' => NULL), "Tue" => array( "temp" => NULL, "visi" => NULL, "weat" => NULL), "Wed" => array( "temp" => NULL, "visi" => NULL, "weat" => NULL), "Thur" => array( "temp" => NULL, "visi" => NULL, "weat" => NULL), "Fri" => array( "temp" => NULL, "visi" => NULL, "weat" => NULL), "Sat" => array( "temp" => NULL, "visi" => NULL, "weat" => NULL), "Sun" => array( "temp" => NULL, "visi" => NULL, "weat" => NULL)); foreach($files as $a){ echo "Hello!"; $str_ar = file($a); for($i=0;$i < count($str_ar);$i++){ $oline = explode(':',$str_ar[$i]); assigning($oline); } } function assigning($line){ for($i=0;$i <= $line.count();$i++){ if($line[$i] == 'Monday'){ if(is_null($week[$Mon[temp]])){ $a = $i+1; $week[$Mon][temp] = $line[$a]; echo $week[$Mon][temp]; } else if (is_null($week[$Mon[visi]])){ $a = $i+1; $week[$Mon][visi] = $line[$a]; echo $week[$Mon][visi]; } else { $a = $i+1; $week[$Mon][weat] = $line[$a]; echo $week[$Mon][weat]; } } else if($line[$i] == 'Tuesday'){ if(is_null($week[$Tue[temp]])){ $a = $i+1; $week[$Tue][temp] = $line[$a]; echo $week[$Tue][temp]; } else if (is_null($week[$Tue[visi]])){ $a = $i+1; $week[$Tue][visi] = $line[$a]; echo "Tue!"; } else { $a = $i+1; $week[$Tue][weat] = $line[$a]; echo "Tue1!"; } } else if($line[$i] == 'Wednesday'){ if(is_null($week[$Wed[temp]])){ $a = $i+1; $week[$Wed][temp] = $line[$a]; echo $week[$Wed][temp]; } else if (is_null($week[$Wed[visi]])){ $a = $i+1; $week[$Wed][visi] = $line[$a]; echo "Wed!"; } else { $a = $i+1; $week[$Wed][weat] = $line[$a]; echo "Wed1!"; } } else if($line[$i] == 'Thursday'){ if(is_null($week[$Thu[temp]])){ $a = $i+1; $week[$Thu][temp] = $line[$a]; echo $week[$Thu][temp]; } else if (is_null($week[$Thu[visi]])){ $a = $i+1; $week[$Thu][visi] = $line[$a]; echo "Thu!"; } else { $a = $i+1; $week[$Thu][weat] = $line[$a]; echo "Thu1!"; } } else if($line[$i] == 'Friday'){ if(is_null($week[$Fri[temp]])){ $a = $i+1; $week[$Fri][temp] = $line[$a]; echo $week[$Fri][temp]; } else if (is_null($week[$Thu[visi]])){ $a = $i+1; $week[$Fri][visi] = $line[$a]; echo "Fri!"; } else { $a = $i+1; $week[$Fri][weat] = $line[$a]; echo "Fri1!"; } } else if($line[$i] == 'Saturday'){ if(is_null($week[$Sat[temp]])){ $a = $i+1; $week[$Sat][temp] = $line[$a]; echo $week[$Sat][temp]; } else if (is_null($week[$Sat[visi]])){ $a = $i+1; $week[$Sat][visi] = $line[$a]; echo "Sat!"; } else { $a = $i+1; $week[$Sat][weat] = $line[$a]; echo "Sat1!"; } } else if($line[$i] == 'Sunday'){ if(is_null($week[$Sun[temp]])){ $a = $i+1; $week[$Sun][temp] = $line[$a]; echo $week[$Sun][temp]; } else if (is_null($week[$Sun[visi]])){ $a = $i+1; $week[$Sun][visi] = $line[$a]; echo "Sun!"; } else { $a = $i+1; $week[$Sun][weat] = $line[$a]; echo "Sun1!"; } } } print_r($week); } ?> </body></html> The print_r dump of the array is:10 Array ( [] => Array ( [temp] => 10 ) ) 5 Array ( [] => Array ( [temp] => 5 ) ) 6 Array ( [] => Array ( [temp] => 6 ) ) 2 Array ( [] => Array ( [temp] => 2 ) ) 1 Array ( [] => Array ( [temp] => 1 ) ) 0 Array ( [] => Array ( [temp] => 0 ) ) -1Array ( [] => Array ( [temp] => -1 ) ) Poor Array ( [] => Array ( [temp] => Poor ) ) Poor Array ( [] => Array ( [temp] => Poor ) ) Poor Array ( [] => Array ( [temp] => Poor ) ) Poor Array ( [] => Array ( [temp] => Poor ) ) Average Array ( [] => Array ( [temp] => Average ) ) Good Array ( [] => Array ( [temp] => Good ) ) ExcellentArray ( [] => Array ( [temp] => Excellent ) ) Rain Array ( [] => Array ( [temp] => Rain ) ) Cloud Array ( [] => Array ( [temp] => Cloud ) ) Drizzle Array ( [] => Array ( [temp] => Drizzle ) ) Snow Array ( [] => Array ( [temp] => Snow ) ) Snow Array ( [] => Array ( [temp] => Snow ) ) Sun Array ( [] => Array ( [temp] => Sun ) ) SunArray ( [] => Array ( [temp] => Sun ) )So just want to loop through that and get the output stated in the initial post.Any ideas?
  2. Sorry for late reply . . didn't realise someone would get back to me so quick. This is my code . . . it needs work and a bit of optimisation: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>BBK ITApps - Web Programming using PHP</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <?php//,'./hoe7b_data/visibility.txt','./hoe7b_data/weather.txt'$file = array('./hoe7b_data/temperature.txt','./hoe7b_data/visibility.txt','./hoe7b_data/weather.txt');$week = array( "Mon" => array('temp' => NULL,'visi' => NULL,'weat' => NULL),"Tue" => array("temp" => NULL,"visi" => NULL,"weat" => NULL),"Wed" => array("temp" => NULL,"visi" => NULL,"weat" => NULL),"Thur" => array("temp" => NULL,"visi" => NULL,"weat" => NULL),"Fri" => array("temp" => NULL,"visi" => NULL,"weat" => NULL),"Sat" => array("temp" => NULL,"visi" => NULL,"weat" => NULL),"Sun" => array("temp" => NULL,"visi" => NULL,"weat" => NULL));foreach($file as $a){loopline(open($a));}function open($dir){//echo "Open $dir ";$filedir = file($dir);return $filedir;}function loopline($str_ar){//$blah = print_r($str_ar);//echo "loopline";for($i=0;$i < count($str_ar);$i++){$hi = $str_ar[$i];explode_a($hi);}}function explode_a($str){$valarray = explode(':',$str);assigning($valarray);} function assigning($line){//print_r($line);//echo "<br/>";for($i=0;$i <= $line.count();$i++){if($line[$i] == 'Monday'){if(is_null($week[$Mon[temp]])){$a = $i+1;$week[$Mon][temp] = $line[$a];echo $week[$Mon][temp];}else if (is_null($week[$Mon[visi]])){$a = $i+1;$week[$Mon][visi] = $line[$a];echo $week[$Mon][visi];}else {$a = $i+1;$week[$Mon][weat] = $line[$a];echo $week[$Mon][weat];}}else if($line[$i] == 'Tuesday'){if(is_null($week[$Tue[temp]])){$a = $i+1;$week[$Tue][temp] = $line[$a];echo $week[$Tue][temp];}else if (is_null($week[$Tue[visi]])){$a = $i+1;$week[$Tue][visi] = $line[$a];echo "Tue!";}else {$a = $i+1;$week[$Tue][weat] = $line[$a];echo "Tue1!";}}else if($line[$i] == 'Wednesday'){if(is_null($week[$Wed[temp]])){$a = $i+1;$week[$Wed][temp] = $line[$a];echo $week[$Wed][temp];}else if (is_null($week[$Wed[visi]])){$a = $i+1;$week[$Wed][visi] = $line[$a];echo "Wed!";}else {$a = $i+1;$week[$Wed][weat] = $line[$a];echo "Wed1!";}}else if($line[$i] == 'Thursday'){if(is_null($week[$Thu[temp]])){$a = $i+1;$week[$Thu][temp] = $line[$a];echo $week[$Thu][temp];}else if (is_null($week[$Thu[visi]])){$a = $i+1;$week[$Thu][visi] = $line[$a];echo "Thu!";}else {$a = $i+1;$week[$Thu][weat] = $line[$a];echo "Thu1!";}}else if($line[$i] == 'Friday'){if(is_null($week[$Fri[temp]])){$a = $i+1;$week[$Fri][temp] = $line[$a];echo $week[$Fri][temp];}else if (is_null($week[$Thu[visi]])){$a = $i+1;$week[$Fri][visi] = $line[$a];echo "Fri!";}else {$a = $i+1;$week[$Fri][weat] = $line[$a];echo "Fri1!";}}else if($line[$i] == 'Saturday'){if(is_null($week[$Sat[temp]])){$a = $i+1;$week[$Sat][temp] = $line[$a];echo $week[$Sat][temp];}else if (is_null($week[$Sat[visi]])){$a = $i+1;$week[$Sat][visi] = $line[$a];echo "Sat!";}else {$a = $i+1;$week[$Sat][weat] = $line[$a];echo "Sat1!";}}else if($line[$i] == 'Sunday'){if(is_null($week[$Sun[temp]])){$a = $i+1;$week[$Sun][temp] = $line[$a];echo $week[$Sun][temp];}else if (is_null($week[$Sun[visi]])){$a = $i+1;$week[$Sun][visi] = $line[$a];echo "Sun!";}else {$a = $i+1;$week[$Sun][weat] = $line[$a];echo "Sun1!";}}}output($week);}function output($final){//print_r($final);foreach($final as $day){echo $too[$Mon][temp];}}?> </body></html>
  3. Hi all,I'm having trouble looping through a multidimensional array to get a specific output.My array looks like this:$week = array( "Mon" = array("temp" => 3, "visi" => 2, "weat" => 4), "Tue" = array("temp" => 8, "visi" => 1, "weat" => 7), "Wed" = array("temp" etc. . .etc ......."Sun" = array("temp" => 8, "visi" => 1, "weat" => 7));I want to loop through the array to get the below output but have failed with foreach and am not confident with non numeric key iteration.MondayTemperature = 3Visibility = 2Weather = 4TuesdayTemperature = 8Visibility = 1Weather = 7etc etc etcSundayTemperature = 8Visibility = 1Weather = 7Any ideas?Thanks in Advance.
  4. Justsomeguy. . .you're a star. The ; at the end of the for loop was causing the problem. It works perfectly now. Thanks
  5. If i comment out $num_rows = mysql_num_rows($resultgk)I can get the following output: <div id ='pitch_div_b'><select id='gkddteams' name='GK' onchange='gk_teams_dd_pitch(this.value,this.name)'><option value='1'>Aston Villa</option></select><div id='pitch_div_a'><label>A list of available Goalkeepers will appear <u>here</u> once you've chosen a team to pick from.</label></div> </div> Sadly it only displays one of the 3 options.I'm getting closer but need a bit of help.
  6. What a great little tool Firebug is! Amazing!I've amended the code that replaces the div with the id of 'pitch_div_c'. See below. <?php$qa=$_GET["qa"];$r=$_GET["r"];$con = mysql_connect("127.0.0.1","root","");if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("webproject", $con);$sqla = ("SELECT id,name FROM teams");$resultgka = mysql_query ($sqla, $con) or exit (mysql_error());$num_rows = mysql_num_rows($resultgka);switch ($r){case ("Change"): echo "<div id ='pitch_div_b'>"; echo "<select id='gkddteams' name='GK' onchange='gk_teams_dd_pitch(this.value,this.name)'>"; for ($i=0; $i < $num_rows; $i++); { $ida = mysql_result($resultgka,$i,0); $namea = mysql_result($resultgka,$i,1); echo "<option value='".$ida."'>".$namea."</option>"; } echo "</select>"; echo "<div id='pitch_div_a'><label>A list of available Goalkeepers will appear <u>here</u> once you've chosen a team to pick from.</label></div> </div>"; break;default: echo "<table> <tr> <td> You Messed Up! </td> </tr> </table>";}?> The GET function is returning this message displayed in Firebug: <div id ='pitch_div_b'><select id='gkddteams' name='GK' onchange='gk_teams_dd_pitch(this.value,this.name)'><br /><b>Warning</b>: mysql_result() [<a href='function.mysql-result'>function.mysql-result</a>]: Unable to jump to row 3 on MySQL result index 3 in <b>C:\Program Files\xampp\htdocs\Web_Project\changechoice.php</b> on line <b>28</b><br /><br /><b>Warning</b>: mysql_result() [<a href='function.mysql-result'>function.mysql-result</a>]: Unable to jump to row 3 on MySQL result index 3 in <b>C:\Program Files\xampp\htdocs\Web_Project\changechoice.php</b> on line <b>29</b><br /><option value=''></option></select><div id='pitch_div_a'><label>A list of available Goalkeepers will appear <u>here</u> once you've chosen a team to pick from.</label></div> </div> any ideas? I've done some investigating but no one answer is conclusive.
  7. Nope, no error gets returned. Should i be refreshing the DOM? Or somethign along those lines?
  8. I've viewed the source of the page when i've returned to the first drop down box via the button and it shows the database values. Just not on the actual page.Haven't implemented the mysql_error yet. Will let you know how i get on.
  9. Sorry, just posted snippets of my code, probably not the best idea.So the problem is that when the user clicks on the change button and the first drop down box appears, it is not populated with anything!So the first drop down is displayed on the page as so: <?php$con = mysql_connect("127.0.0.1","root","");if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("webproject", $con);$sql = ("SELECT id,name FROM teams");$resultgk = mysql_query ($sql, $con);$num_rows = mysql_num_rows($resultgk);mysql_close($con);?><form> <fieldset id='pitchform'> <legend id='pitchlegend'>4-4-2</legend> <label id= 'pitchgklabel'>GOALKEEPER</label> <div id = 'pitch_div_c'> <div id ='pitch_div_b'> <select id='gkddteams' name='GK' onchange='gk_teams_dd_pitch(this.value,this.name)'> <?php for ($i=0; $i < $num_rows; $i++) { $id = mysql_result($resultgk,$i,0); $name = mysql_result($resultgk,$i,1); echo "<option value='" .$id. "'>" .$name. "</option>"; } ?> </select> <div id='pitch_div_a'><label>A list of available Goalkeepers will appear <u>here</u> once you've chosen a team to pick from.</label></div> </div> </div> </fieldset></form> With the onchange activated goes to the following js code: var xmlhttp;var lineup = new Array();function gk_teams_dd_pitch(pitch_team_choice,pitch_team_pos_name){xmlhttp=GetXmlHttpObject();if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } if (pitch_team_pos_name == "GK") { var url="getplayerlist.php"; url=url+"?q="+pitch_team_choice+"&qa="+pitch_team_pos_name; url=url+"&sid="+Math.random(); alert (url); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } else if (pitch_team_pos_name == "RB") { var url="getplayerlist.php"; url=url+"?q="+pitch_team_choice+"&qa="+pitch_position; url=url+"&sid="+Math.random(); alert (url); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } }//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------function stateChanged(){if (xmlhttp.readyState==4){document.getElementById("pitch_div_a").innerHTML=xmlhttp.responseText;}}//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------function gk_teams_dd_pitch_chosen(pitch_player_choice,pitch_team_pos_name_chosen){xmlhttp=GetXmlHttpObject();if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } if (pitch_team_pos_name_chosen == "GK") { var url="chooseplayer.php"; url=url+"?r="+pitch_player_choice+"&qa="+pitch_team_pos_name_chosen; url=url+"&sid="+Math.random(); alert (url); xmlhttp.onreadystatechange=stateChanged_chosen; xmlhttp.open("GET",url,true); xmlhttp.send(null); } else if (pitch_team_pos_name_chosen == "NOTGK") { var urla="changechoice.php"; urla=urla+"?r="+pitch_player_choice+"&qa="+pitch_team_pos_name_chosen; urla=urla+"&sid="+Math.random(); alert (urla); xmlhttp.onreadystatechange=stateChanged_change; xmlhttp.open("GET",urla,true); xmlhttp.send(null); } }//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------function stateChanged_chosen(){if (xmlhttp.readyState==4){document.getElementById("pitch_div_b").innerHTML=xmlhttp.responseText;}}//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------function stateChanged_change(){if (xmlhttp.readyState==4){document.getElementById("pitch_div_c").innerHTML=xmlhttp.responseText;}}//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null;}//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- This then displays the second drop-down box below the first dorp down, as shown below: <?php$qa=$_GET["qa"];$q=$_GET["q"]; $con = mysql_connect('127.0.0.1', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("webproject", $con); $sqla= "SELECT pl.surname, pl.position_id, t.id, pl.pl_id FROM players AS pl JOIN position AS po ON po.p_id = pl.position_id JOIN teams AS t ON t.id = pl.team_id WHERE t.id = '".$q."' AND pl.position_id = '1'";$resultgk = mysql_query($sqla); switch ($qa) {//----------------------------------------------------------------------------------------------------------------------------------------------------------------1 case ("GK"):echo "<td>"; echo "<select id='gkddteamstwo' name='GK' onchange='gk_teams_dd_pitch_chosen(this.value,this.name)'>"; while($row = mysql_fetch_array($resultgk)) { echo "<option value='" . $row['pl_id'] . "'>" . $row['surname'] . "</option>"; } echo "</select>"; echo "</td>"; echo "<label id='confirmposlabel3'>Please choose a Goalkeeper</label>"; break; default: echo "I don't know how....but you messed up!"; break; } mysql_close($con);?> The second drop down box then has an onchange to remove both drop down boxes and replace with this: <?php$qa=$_GET["qa"];$r=$_GET["r"];switch ($r){case ("7"): echo "<label id='confirmposlabel'>Your GoalKeeper is:</label> <label id='confirmposlabel2'>$r</label> <input id='button2' type='button' method='post' name='NOTGK' value='Change' onclick='gk_teams_dd_pitch_chosen(this.value,this.name)'/>"; break;default: echo "<table> <tr> <td> You messed up! </td> </tr> </table>";}?> The button in the above code has an onchange event pointing to the function gk_teams_dd_pitch_chosen, which goes full circle and replaces the first drop down bos code. <?php$qa=$_GET["qa"];$r=$_GET["r"];switch ($r){case ("Change"): echo "<div id = 'pitch_div_c'>"; echo "<div id ='pitch_div_b'>"; echo "<select id='gkddteams' name='GK' onchange='gk_teams_dd_pitch(this.value,this.name)'>"; for ($i=0; $i < $num_rows; $i++); { echo "$id = mysql_result($resultgk,$i,0)"; echo "$name = mysql_result($resultgk,$i,1)"; echo "<option value='".$id."'>".$name."</option>"; } echo "</select>"; echo "<div id='pitch_div_a'><label>A list of available Goalkeepers will appear <u>here</u> once you've chosen a team to pick from.</label></div> </div>"; echo "</div>"; break;default: echo "<table> <tr> <td> You Messed Up! </td> </tr> </table>";}?> sorry to have described it again, my mistake for leaving code out at the start.
  10. Ah yes, thanks for that Justsomeguy. Feeling slightly embarrassed about that. It works perfectly now.I have come across another problem with my code that is related. I have a drop down box populated via a mysql db. There is an onchange event attached to it that calls a javascript function. This javascript function then creates an object via Ajax and replaces the <div> (just a label) below the first drop down with another drop down. This second drop down box also has an onchange event which calls a function that replaces both drop (a div within a div, within a div!) down boxes with an HTML label and a button. The Button has an onclick event that calls another jscript function that replaces the label and button with the previous code, showing only one drop down box (as from the start). My problem is that when the user clicks on the change button and the first drop down box appears, it is not populated with anything!I know its probably got something to do with the way I’ve echo out the for loop in "Replace label and button with first drop down's code".I would preferably want to avoid reloading the page.any ideas?The mainbody of the page: <form> <fieldset id='pitchform'> <legend id='pitchlegend'>4-4-2</legend> <label id= 'pitchgklabel'>GOALKEEPER</label> <div id = 'pitch_div_c'> <div id ='pitch_div_b'> <select id='gkddteams' name='GK' onchange='gk_teams_dd_pitch(this.value,this.name)'> <?php for ($i=0; $i < $num_rows; $i++) { $id = mysql_result($resultgk,$i,0); $name = mysql_result($resultgk,$i,1); echo "<option value='" .$id. "'>" .$name. "</option>"; } ?> </select> <div id='pitch_div_a'><label>A list of available Goalkeepers will appear <u>here</u> once you've chosen a team to pick from.</label></div> </div> </div> </fieldset></form> Javascript functions var xmlhttp;var lineup = new Array();function gk_teams_dd_pitch(pitch_team_choice,pitch_team_pos_name){xmlhttp=GetXmlHttpObject();if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } if (pitch_team_pos_name == "GK") { var url="getplayerlist.php"; url=url+"?q="+pitch_team_choice+"&qa="+pitch_team_pos_name; url=url+"&sid="+Math.random(); alert (url); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } else if (pitch_team_pos_name == "RB") { var url="getplayerlist.php"; url=url+"?q="+pitch_team_choice+"&qa="+pitch_position; url=url+"&sid="+Math.random(); alert (url); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } }//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------function stateChanged(){if (xmlhttp.readyState==4){document.getElementById("pitch_div_a").innerHTML=xmlhttp.responseText;}}//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------function gk_teams_dd_pitch_chosen(pitch_player_choice,pitch_team_pos_name_chosen){xmlhttp=GetXmlHttpObject();if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } if (pitch_team_pos_name_chosen == "GK") { var url="chooseplayer.php"; url=url+"?r="+pitch_player_choice+"&qa="+pitch_team_pos_name_chosen; url=url+"&sid="+Math.random(); alert (url); xmlhttp.onreadystatechange=stateChanged_chosen; xmlhttp.open("GET",url,true); xmlhttp.send(null); } else if (pitch_team_pos_name_chosen == "NOTGK") { var urla="changechoice.php"; urla=urla+"?r="+pitch_player_choice+"&qa="+pitch_team_pos_name_chosen; urla=urla+"&sid="+Math.random(); alert (urla); xmlhttp.onreadystatechange=stateChanged_change; xmlhttp.open("GET",urla,true); xmlhttp.send(null); } }//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------function stateChanged_chosen(){if (xmlhttp.readyState==4){document.getElementById("pitch_div_b").innerHTML=xmlhttp.responseText;}}//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------function stateChanged_change(){if (xmlhttp.readyState==4){document.getElementById("pitch_div_c").innerHTML=xmlhttp.responseText;}}//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null;}//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- First Checkbox appear onchange echo "<select id='gkddteamstwo' name='GK' onchange='gk_teams_dd_pitch_chosen(this.value,this.name)'>"; while($row = mysql_fetch_array($resultgk)) { echo "<option value='" . $row['pl_id'] . "'>" . $row['surname'] . "</option>"; } echo "</select>"; echo "</td>"; echo "<label id='confirmposlabel3'>Please choose a Goalkeeper</label>"; Replace both drop down with label and button echo "<label id='confirmposlabel'>Your GoalKeeper is:</label> <label id='confirmposlabel2'>$r</label> <input id='button2' type='button' method='post' name='NOTGK' value='Change' onclick='gk_teams_dd_pitch_chosen(this.value,this.name)'/>"; Replace label and button with first drop down's code. echo "<div id = 'pitch_div_c'>"; echo "<div id ='pitch_div_b'>"; echo "<select id='gkddteams' name='GK' onchange='gk_teams_dd_pitch(this.value,this.name)'>"; echo "<?php"; for ($i=0; $i < $num_rows; $i++); echo "{"; echo '"{$id = mysql_result($resultgk,$i,0);"'; echo '"$name = mysql_result($resultgk,$i,1);"'; echo "echo '<option value=''.$id.'>'.$name.''</option>'';'"; echo "}"; echo "?>"; echo "</select>"; echo "<div id='pitch_div_a'><label>A list of available Goalkeepers will appear <u>here</u> once you have chosen a team to pick from.</label></div> </div>"; I apologise for the poor layout of the code.
  11. Yeh sorry about that, as I read through my post it did occur to me that this was more Jscript related.Bit of a newby but is there a way of preventing .push() from outputting the array length afterward and just storing the value? Or is there a better method. I'm looking at splice()Thanks for the advice.
  12. Hi all,How do i go about structuring my Javascript function to expect multiple calls from 11 different drop down boxes.Each drop down box has an onchange event which sends 'this.value' to that function. What I want is for that function to collect those values in an array.Do i have to declare 11 seperate parameters?Below is one of the drop down's. switch ($qa) {//----------------------------------------------------------------------------------------------------------------------------------------------------------------1 case ("GK"): echo "<td>"; echo "<select id='ddowna' onchange='myfunc(this.value)'>"; while($row = mysql_fetch_array($resultgk)) { echo "<option value='" . $row['id'] . "'>" . $row['surname'] . "</option>"; } echo "</select>"; echo "</td>"; break; Below is the piss poor function which grabs one value, but no more than one: function myfunc(blah){var po = blah;var myCars = [po];for(i=0;i<myCars.length;i++)document.write(myCars[i]); }
  13. Nice one, was really just working on basic php but seem to have crossed onto Jscript. Will read up.Thanks for the help.
  14. Ah ok brilliant thanks.Just for my knowledge bank, why does this.value not need the quotes?
  15. I want to use that $pos variable in the sql statement on the php script. Something like below: $sql=("SELECT surname FROM players WHERE players.team_id ='".$q."'and WHERE players.position = '".$q."'"); Is this still a possibility?
×
×
  • Create New...