943,741 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 756
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jul 14th, 2009
0

Re: PHP :Reading from a file

Well for this, you might have to modify the survey file a bit. Or perhaps you need some other file. I assumed survey.txt contains the questions.
From your point, i think it contains the answers (or how many people chose which option), but yes the way i told you, it seems to be appropriate. You can read from the file in a similar way i wrote above. And then you can calculate your answers and show them in a bar graph.
Reputation Points: 11
Solved Threads: 12
Junior Poster in Training
sikka_varun is offline Offline
94 posts
since Dec 2008
Jul 14th, 2009
0

Re: PHP :Reading from a file

sikka_varun thanks for your help but still i dont know how to write it in the code would you please help me with it since i need to submitt it by thursday .thank u
Reputation Points: 10
Solved Threads: 0
Newbie Poster
BabyEyes is offline Offline
18 posts
since Apr 2008
Jul 14th, 2009
0

Re: PHP :Reading from a file

can you please be more specific in your requirement, or have you made somethng?? if yes, please post it here... i will help you out with this...
Reputation Points: 11
Solved Threads: 12
Junior Poster in Training
sikka_varun is offline Offline
94 posts
since Dec 2008
Jul 16th, 2009
0

Re: PHP :Reading from a file

hi, i still couldnt figure out where is the problme it is not showing the right answer.
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $fa= file("survey.txt");
  3. explode(" ",$fa[$i]);
  4.  
  5. foreach($fa as $ansA) {
  6. $smoke1=0;
  7. $smoke2=0;
  8. $eat1=0;
  9. $eat2=0;
  10. $eat3=0;
  11. $g1=0;
  12. $g2=0;
  13. $age1=0;
  14. $age2=0;
  15. $age3=0;
  16. $h1=0;
  17. $h2=0;
  18. $h3=0;
  19.  
  20. for( $i=0 ;$i<sizeof($fa) ;$i++) {
  21. if($ansA[0]==1)
  22. $smoke1++;
  23. else
  24. $smoke2++;
  25.  
  26.  
  27. if($ansA[1]==1)
  28. $eat1++;
  29. else if($ansA[1]==2)
  30. $eat2++;
  31. else
  32. $eat3++;
  33.  
  34.  
  35. if($ansA[2]==1)
  36. $g1++;
  37. else
  38. $g2++;
  39.  
  40.  
  41. if($ansA[3]==1)
  42. $age1++;
  43. else if($ansA[3]==2)
  44. $age2++;
  45. else
  46. $age3++;
  47.  
  48.  
  49.  
  50. if($ansA[4]==1)
  51. $h1++;
  52. else if($ansA[4]==2)
  53. $h2++;
  54. else
  55. $h3++;
  56. }
  57. }
  58. ?>

why the answer is not getting it for all the questions
Reputation Points: 10
Solved Threads: 0
Newbie Poster
BabyEyes is offline Offline
18 posts
since Apr 2008
Jul 16th, 2009
0

Re: PHP :Reading from a file

guysssssssss please help ((
Reputation Points: 10
Solved Threads: 0
Newbie Poster
BabyEyes is offline Offline
18 posts
since Apr 2008
Jul 16th, 2009
0

Re: PHP :Reading from a file

i have finished that coit works fine. thanks for those who replay to my message in order to help .
Reputation Points: 10
Solved Threads: 0
Newbie Poster
BabyEyes is offline Offline
18 posts
since Apr 2008
Jul 17th, 2009
0

Re: PHP :Reading from a file

Hi there,
Try this:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $fa= file("survey.txt");
  3. $array = explode(" ",$fa);
  4.  
  5. foreach($array as $ansA) {
  6. $smoke1=0;
  7. $smoke2=0;
  8. $eat1=0;
  9. $eat2=0;
  10. $eat3=0;
  11. $g1=0;
  12. $g2=0;
  13. $age1=0;
  14. $age2=0;
  15. $age3=0;
  16. $h1=0;
  17. $h2=0;
  18. $h3=0;
  19.  
  20. for( $i=0 ;$i<sizeof($ansA) ;$i++) {
  21. if($ansA[0]==1)
  22. $smoke1++;
  23. else
  24. $smoke2++;
  25.  
  26.  
  27. if($ansA[1]==1)
  28. $eat1++;
  29. else if($ansA[1]==2)
  30. $eat2++;
  31. else
  32. $eat3++;
  33.  
  34.  
  35. if($ansA[2]==1)
  36. $g1++;
  37. else
  38. $g2++;
  39.  
  40.  
  41. if($ansA[3]==1)
  42. $age1++;
  43. else if($ansA[3]==2)
  44. $age2++;
  45. else
  46. $age3++;
  47.  
  48.  
  49.  
  50. if($ansA[4]==1)
  51. $h1++;
  52. else if($ansA[4]==2)
  53. $h2++;
  54. else
  55. $h3++;
  56. }
  57. }
  58. ?>
Your variables were all a little messed up (order wise) and you didn't put anything equal to the explode() expression at the top.
Reputation Points: 49
Solved Threads: 22
Junior Poster
Menster is offline Offline
175 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Problem in submitting and deleting records in PHP ??
Next Thread in PHP Forum Timeline: script runing automatically





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC