Please help me. I do not know how to do it and not sure which type of code can do this as the simplest method. 1 ) I have to design a simple website to show up 10 name of people e.g. a,b,c,d,e,f,g,h,i,j 2) then set up a button, when you click it, it will random them into new order and assign them with score e.g. - after click a "show score" button the screen will show something like ---------------------------- Test 1 score b = 10 d = 9 i = 8 a = 7 g = 6 h = 5 j = 4 c = 3 e = 2 f = 1 ------------------------------- 3) click "next" button to go to next page 4) Next page will select only the top 5 people who score most and show the screen as below ------------------------------- Highest 5 are b = 10 d = 9 i = 8 a = 7 g = 6 ------------------------------- 5 ) click "next score after test 2" button 6 ) It will randomly assign the score to each person again and the screen will show something like below. ----------------------- test 2 score g = 10 b = 9 a = 8 h = 7 e = 6 i = 5 f = 4 j = 3 c = 2 d = 1 --------------------------- 7) click "next" button 8) it will go to new page that show sum of test 1, test 2 score for each person like screen below --------------------------- b = 19 g = 16 a = 15 i = 13 h = 12 d = 10 e = 8 j = 7 c = 5 f = 5 --------------------------------------------------------- That's all. No need for any back ground or decoration on the webpage. Could anyone help me to let me know how to write the webpage to be like this as simplest as possible. Thank you so much. ---------------------------
<?php session_start(); $name=array("a","b","c","d","e","f","g","h","i","j"); $button=array("Show Score","Next","Show Score","Score Sum"); $test=1; if(isset($_POST['test0'])){ echo "Test 1 score <br/>"; for($a=0;$a<10;$a++){ $name_score[$a]=rand(1,10); } arsort($name_score); foreach ($name_score as $key) { $name_sort_score[]=$key; } for($a=0;$a<10;$a++){ echo $name[$a]." = ".$name_sort_score[$a]."<br/>"; $_SESSION["score_$a"]=$name_sort_score[$a]; } $test=2; } if(isset($_POST['test1'])){ echo "Highest 5 are <br/>"; for($a=0;$a<5;$a++){ echo $name[$a]." = ".$_SESSION["score_$a"]."<br/>"; } $test=3; } if(isset($_POST['test2'])){ echo "Test 2 score <br/>"; for($a=0;$a<10;$a++){ $name_score[]=rand(1,10); } arsort($name_score); foreach($name_score as $key) { $name_sort_score[]=$key; } for($a=0;$a<10;$a++){ echo $name[$a]." = ".$name_sort_score[$a]."<br/>"; $_SESSION["score1_$a"]=$name_sort_score[$a]; } $test=4; } if(isset($_POST['test3'])){ echo "Total score <br/>"; for($a=0;$a<10;$a++){ $final_score[]=$_SESSION["score_$a"]+$_SESSION["score1_$a"]; echo $name[$a]." = ".$final_score[$a]."<br/>"; } $test=1; } ?> <form action="" method="post"> <input type="submit" name="test<?php echo $test-1;?>" value="<?php echo $button[$test-1];?>"/> </form> PHP:
Thank you for your code. Can you please check the last 3 lines of codes if there is any error because it shows an error when I try the code. Thank you so much again.
The last 3 lines are html lines so i don't see what error could you get but post your error message here.
I tried to put whole code in HTML testbed online "http://www.jmarshall.com/easy/html/testbed.html" and it doesn't seem to be OK. Could you please give me an advice. Thank you again. ps: I tested the code in Dreamweaver. and the error is the code of "<?php echo $button[$test-1];?>" appears inside the button. However I don't have dreamweaver on my laptop which I am using now. So please try to input the code on website HTML testbed to see what output the screen will show. Thank you.
You must put all the code inside a php page like test.php,otherwise the script won't work.Or you can add this in .htaccess and then it doesn't matter if page is .php or .html RemoveHandler .html .htm AddType application/x-httpd-php .php .htm .html Code (markup):
Where to put the code? inside or outside php bracket? What I did just now is copy your code into notepad and name it as .html And triedto add your new code (2 lines code) into the previous code. Howeverwhen I open the file with firefox, it still shows a screen that full of code and 1 button which got some code inside. Please see the image below. I print the screen to show you below.
If you don't have a .htaccess file just create one and paste the code but you must have installed apache+php to read php pages
Oh, Thank you so much. I have tried on my PC that got apache+php installed and it works brilliant!!! I will let you know if there is any further question.
Hi again, I have just checked again to see the output. I have noticed something which is not right. So could you please have a look and help me again. 1) First, each person cannot have the same score. So if "a" got 10 point, "b" cannot got 10 point....something like that.... (but it's ok if summation score are equal) 2) The score has to be randomly assigned to each random person which don't need to be in order from "a" to "j". But from your code, the score of a is always higher than b > c > d > e > f > g.....> i > j , respectively.. what I want is... b can get higher score than a, j can get higher score than c....something like that Thank you for your help again.
Now should work like you said <?php session_start(); $name=array("a","b","c","d","e","f","g","h","i","j"); sort($name); $button=array("Show Score","Next","Show Score","Total Score"); $test=1; $count_name=count($name); $top=5; $numbers=array(); for($a=0;$a<$count_name;$a++){ $b=rand(1,$count_name); if(in_array($b,$numbers)) { $a--; }else{ $numbers[]=$b; } } function sort_array($a,$skey,$order) { foreach($a as $k=>$v) { $b[$k]=$v[$skey]; } if($order=="asc"){ arsort($b); }else{ asort($b); } foreach($b as $key=>$val) { $c[]=$a[$key]; } return $c; } if(isset($_POST['test0'])){ echo "Test 1 results <br/>"; for($a=0;$a<$count_name;$a++){ $name_score[$a]=$numbers[$a]; } foreach($name_score as $key) { $name_sort_score[]=$key; } for($a=0;$a<$count_name;$a++){ echo $name[$numbers[$a]-1]." = ".$name_sort_score[$numbers[$a]-1]."<br/>"; $_SESSION["score_$a"]=$name_sort_score[$numbers[$a]-1]; $_SESSION["name_$a"]=$name[$numbers[$a]-1]; $arr[]=array($name[$numbers[$a]-1] => $name_sort_score[$numbers[$a]-1]); $_SESSION["scores"][$a]=$arr[$a]; } $test=2; } if(isset($_POST['test1'])){ echo "Highest $top are <br/>"; for($a=0;$a<$count_name;$a++){ $highest_score[]=array('name'=>$_SESSION["name_$a"],'nr'=>$_SESSION["score_$a"]); $highest_scores=sort_array($highest_score,'nr',"asc"); } $test=3; } if(isset($_POST['test1'])){ for($a=0;$a<$top;$a++){ echo $highest_scores[$a]['name']." = ".$highest_scores[$a]['nr']."<br/>"; } } if(isset($_POST['test2'])){ echo "Test 2 results <br/>"; for($a=0;$a<$count_name;$a++){ $name_score[]=$numbers[$a]; } foreach($name_score as $key) { $name_sort_score[]=$key; } for($a=0;$a<$count_name;$a++){ echo $name[$numbers[$a]-1]." = ".$name_sort_score[$numbers[$a]-1]."<br/>"; $_SESSION["score1_$a"]=$name_sort_score[$numbers[$a]-1]; $_SESSION["name1_$a"]=$name[$numbers[$a]-1]; $arr1[]=array($name[$numbers[$a]-1] => $name_sort_score[$numbers[$a]-1]); $_SESSION["scores1"][$a]=$arr1[$a]; } $test=4; } if(isset($_POST['test3'])){ echo "Total score <br/>"; for($a=0;$a<$count_name;$a++){ $final_score[]=$_SESSION["score_$a"]+$_SESSION["score1_$a"]; } $test=1; for($a=0;$a<$count_name;$a++){ $numbers_test[]=array('name'=>$_SESSION["name_$a"],'nr'=>$_SESSION["score_$a"]); $numbers_test1[]=array('name'=>$_SESSION["name1_$a"],'nr'=>$_SESSION["score1_$a"]); } $numbers_test=sort_array($numbers_test,'name'); $numbers_test1=sort_array($numbers_test1,'name'); for($a=0;$a<$count_name;$a++){ $sumb[]=$numbers_test[$a]['nr']+$numbers_test1[$a]['nr']; $sort_total[]=array('name'=>$name[$a],'nr'=>$sumb[$a]); $sort_total_order=sort_array($sort_total,'nr',"asc"); } } if(isset($_POST['test3'])){ for($a=0;$a<$count_name;$a++){ echo $sort_total_order[$a]['name']." = ".$sort_total_order[$a]['nr']."<br/>"; } } ?> <form action="" method="post"> <input type="submit" name="test<?php echo $test-1;?>" value="<?php echo $button[$test-1];?>"/> </form> PHP:
Hi, Here is the error I got on last page (Total score) Also, could you please make the "test 1 result" and "test 2 result" to be in the order from "person who got highest score" to "person who got lowest score". (e.g. b=10 j=9 d=8 ... ... ... e=1 ) Thank you so much. - Can I ask another question. Not sure if it's hard to do... Can we write these code in a few html files? something like html code file 1 will show result of test score 1, and when click "next" it will go to file 2 which show the screen result 2........something like that................... or html don't do calculation (add, subtract...) so we have to do in php? - Next question, if it's not hard please advise me how to do..... Assume there are 10 students in the class. And the score will show up like what you have done. What if we do a bit more complicated work on the page as follow First page: The header is "show score" and there will be 11 buttons shown below which consist of (a) (b) (c) (d) (e) (f) (g) (h) (i) (j) and (next) And if we click (a) it will show up only a's score (other people's score will not show up), next if click (f), it will show f's score (and a's score which was previously clicked will still be shown there too). And if we click (next) it will go to the page that show highest 5 score, test 2 score, total score as we you did before. Something like that. Can you please tell me if it's complicated to add this function? Thank you so much.
Here is the code: <?php session_start(); $name=array("a","b","c","d","e","f","g","h","i","j"); sort($name); $button=array("Start","Next","Next","Next"); $test=1; $count_name=count($name); $top=5; $numbers=array(); for($a=0;$a<$count_name;$a++){ $b=rand(1,$count_name); if(in_array($b,$numbers)) { $a--; }else{ $numbers[]=$b; } } function sort_array($a,$skey,$order) { foreach($a as $k=>$v) { $b[$k]=$v[$skey]; } if($order=="asc"){ arsort($b); }else{ asort($b); } foreach($b as $key=>$val) { $c[]=$a[$key]; } return $c; } if(isset($_POST['test0'])){ for($a=0;$a<$count_name;$a++){ $name_score[$a]=$numbers[$a]; } foreach($name_score as $key) { $name_sort_score[]=$key; } for($a=0;$a<$count_name;$a++){ $_SESSION["score_$a"]=$name_sort_score[$numbers[$a]-1]; $_SESSION["name_$a"]=$name[$numbers[$a]-1]; $arr[]=array($name[$numbers[$a]-1] => $name_sort_score[$numbers[$a]-1]); $_SESSION["scores"][$a]=$arr[$a]; } $test=2; } if(isset($_POST['test0'])){ for($a=0;$a<$count_name;$a++){ $highest_score[]=array('name'=>$_SESSION["name_$a"],'nr'=>$_SESSION["score_$a"]); $highest_scores=sort_array($highest_score,'nr',"asc"); } for($a=0;$a<$count_name;$a++){ $_SESSION["person_score"][$a]=$highest_scores[$a]['name']; $_SESSION["person_score_nr"][$a]=$highest_scores[$a]['nr']; } } for($a=0;$a<$count_name;$a++){ if(isset($_POST["name_$a"])){ for($b=0;$b<$count_name;$b++){ if($_SESSION["person_score"][$b]==$name[$a]){ $_SESSION["show_all_scores"][$a]=$name[$a]." score = ".$_SESSION["person_score_nr"][$b]; } } for($c=0;$c<$count_name;$c++){ if($_SESSION["show_all_scores"][$c]!=""){ echo $_SESSION["show_all_scores"][$c]."<br/>"; } } $test=2; } } if($test!=2){ unset($_SESSION["show_all_scores"]); } if(isset($_POST['test1'])){ echo "Highest $top are <br/>"; for($a=0;$a<$count_name;$a++){ $highest_score[]=array('name'=>$_SESSION["name_$a"],'nr'=>$_SESSION["score_$a"]); $highest_scores=sort_array($highest_score,'nr',"asc"); } $test=3; } if(isset($_POST['test1'])){ for($a=0;$a<$top;$a++){ echo $highest_scores[$a]['name']." = ".$highest_scores[$a]['nr']."<br/>"; } } if(isset($_POST['test2'])){ for($a=0;$a<$count_name;$a++){ $name_score[]=$numbers[$a]; } foreach($name_score as $key) { $name_sort_score[]=$key; } for($a=0;$a<$count_name;$a++){ $_SESSION["score1_$a"]=$name_sort_score[$numbers[$a]-1]; $_SESSION["name1_$a"]=$name[$numbers[$a]-1]; $arr1[]=array($name[$numbers[$a]-1] => $name_sort_score[$numbers[$a]-1]); $_SESSION["scores1"][$a]=$arr1[$a]; } $test=4; } if(isset($_POST['test2'])){ for($a=0;$a<$count_name;$a++){ $highest_score[]=array('name'=>$_SESSION["name1_$a"],'nr'=>$_SESSION["score1_$a"]); $highest_scores=sort_array($highest_score,'nr',"asc"); } for($a=0;$a<$count_name;$a++){ $_SESSION["person_score1"][$a]=$highest_scores[$a]['name']; $_SESSION["person_score_nr1"][$a]=$highest_scores[$a]['nr']; } } for($a=0;$a<$count_name;$a++){ if(isset($_POST["name1_$a"])){ for($b=0;$b<$count_name;$b++){ if($_SESSION["person_score1"][$b]==$name[$a]){ $_SESSION["show_all_scores1"][$a]=$name[$a]." score = ".$_SESSION["person_score_nr1"][$b]; } } for($c=0;$c<$count_name;$c++){ if($_SESSION["show_all_scores1"][$c]!=""){ echo $_SESSION["show_all_scores1"][$c]."<br/>"; } } $test=4; } } if($test!=4){ unset($_SESSION["show_all_scores1"]); } if(isset($_POST['test3'])){ echo "Total score <br/>"; for($a=0;$a<$count_name;$a++){ $final_score[]=$_SESSION["score_$a"]+$_SESSION["score1_$a"]; } $test=1; for($a=0;$a<$count_name;$a++){ $numbers_test[]=array('name'=>$_SESSION["name_$a"],'nr'=>$_SESSION["score_$a"]); $numbers_test1[]=array('name'=>$_SESSION["name1_$a"],'nr'=>$_SESSION["score1_$a"]); } $numbers_test=sort_array($numbers_test,'name',"desc"); $numbers_test1=sort_array($numbers_test1,'name',"desc"); for($a=0;$a<$count_name;$a++){ $sumb[]=$numbers_test[$a]['nr']+$numbers_test1[$a]['nr']; $sort_total[]=array('name'=>$name[$a],'nr'=>$sumb[$a]); $sort_total_order=sort_array($sort_total,'nr',"asc"); } } if(isset($_POST['test3'])){ for($a=0;$a<$count_name;$a++){ echo $sort_total_order[$a]['name']." = ".$sort_total_order[$a]['nr']."<br/>"; } } ?> <form action="" method="post"> <?php if($test==2){ ?> <div style="display: block;"> <?php for($a=0;$a<$count_name;$a++){ ?> <input type="submit" name="name_<?php echo $a;?>" value="<?php echo $name[$a];?>"/> <?php } ?> <?php } ?> <?php if($test==4){ ?> <?php for($a=0;$a<$count_name;$a++){ ?> <input type="submit" name="name1_<?php echo $a;?>" value="<?php echo $name[$a];?>"/> <?php } ?> <?php } ?> <input type="submit" name="test<?php echo $test-1;?>" value="<?php echo $button[$test-1];?>"/> </div> </form> PHP: