PHP :Reading from a file

Reply

Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: PHP :Reading from a file

 
0
  #11
Jul 14th, 2009
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.
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 18
Reputation: BabyEyes is an unknown quantity at this point 
Solved Threads: 0
BabyEyes BabyEyes is offline Offline
Newbie Poster

Re: PHP :Reading from a file

 
0
  #12
Jul 14th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: PHP :Reading from a file

 
0
  #13
Jul 14th, 2009
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...
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 18
Reputation: BabyEyes is an unknown quantity at this point 
Solved Threads: 0
BabyEyes BabyEyes is offline Offline
Newbie Poster

Re: PHP :Reading from a file

 
0
  #14
Jul 16th, 2009
hi, i still couldnt figure out where is the problme it is not showing the right answer.
  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
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 18
Reputation: BabyEyes is an unknown quantity at this point 
Solved Threads: 0
BabyEyes BabyEyes is offline Offline
Newbie Poster

Re: PHP :Reading from a file

 
0
  #15
Jul 16th, 2009
guysssssssss please help ((
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 18
Reputation: BabyEyes is an unknown quantity at this point 
Solved Threads: 0
BabyEyes BabyEyes is offline Offline
Newbie Poster

Re: PHP :Reading from a file

 
0
  #16
Jul 16th, 2009
i have finished that coit works fine. thanks for those who replay to my message in order to help .
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 171
Reputation: Menster is an unknown quantity at this point 
Solved Threads: 22
Menster's Avatar
Menster Menster is offline Offline
Junior Poster

Re: PHP :Reading from a file

 
0
  #17
Jul 17th, 2009
Hi there,
Try this:
  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.
$me = new Person();
if (isset($_COOKIE)){
$me->eat($_COOKIE);
} else { $me->starve(); }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC