| | |
PHP :Reading from a file
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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.
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.
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...
•
•
Join Date: Apr 2008
Posts: 18
Reputation:
Solved Threads: 0
hi, i still couldnt figure out where is the problme it is not showing the right answer.
why the answer is not getting it for all the questions
PHP Syntax (Toggle Plain Text)
<?php $fa= file("survey.txt"); explode(" ",$fa[$i]); foreach($fa as $ansA) { $smoke1=0; $smoke2=0; $eat1=0; $eat2=0; $eat3=0; $g1=0; $g2=0; $age1=0; $age2=0; $age3=0; $h1=0; $h2=0; $h3=0; for( $i=0 ;$i<sizeof($fa) ;$i++) { if($ansA[0]==1) $smoke1++; else $smoke2++; if($ansA[1]==1) $eat1++; else if($ansA[1]==2) $eat2++; else $eat3++; if($ansA[2]==1) $g1++; else $g2++; if($ansA[3]==1) $age1++; else if($ansA[3]==2) $age2++; else $age3++; if($ansA[4]==1) $h1++; else if($ansA[4]==2) $h2++; else $h3++; } } ?>
why the answer is not getting it for all the questions
Hi there,
Try this:
Your variables were all a little messed up (order wise) and you didn't put anything equal to the explode() expression at the top.
Try this:
PHP Syntax (Toggle Plain Text)
<?php $fa= file("survey.txt"); $array = explode(" ",$fa); foreach($array as $ansA) { $smoke1=0; $smoke2=0; $eat1=0; $eat2=0; $eat3=0; $g1=0; $g2=0; $age1=0; $age2=0; $age3=0; $h1=0; $h2=0; $h3=0; for( $i=0 ;$i<sizeof($ansA) ;$i++) { if($ansA[0]==1) $smoke1++; else $smoke2++; if($ansA[1]==1) $eat1++; else if($ansA[1]==2) $eat2++; else $eat3++; if($ansA[2]==1) $g1++; else $g2++; if($ansA[3]==1) $age1++; else if($ansA[3]==2) $age2++; else $age3++; if($ansA[4]==1) $h1++; else if($ansA[4]==2) $h2++; else $h3++; } } ?>
$me = new Person();
if (isset($_COOKIE)){
$me->eat($_COOKIE);
} else { $me->starve(); }
if (isset($_COOKIE)){
$me->eat($_COOKIE);
} else { $me->starve(); }
![]() |
Similar Threads
- php reading a text file ..... help (PHP)
- php.ini file not being read (PHP)
- Error Message Concerning Reading File From A Drive (C++)
- reading a file into code (Java)
Other Threads in the PHP Forum
- Previous Thread: Problem in submitting and deleting records in PHP ??
- Next Thread: script runing automatically
Views: 501 | Replies: 16
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error file files folder form forms function functions google howtowriteathesis href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop parse paypal pdf php problem provider query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table template tutorial update updates upload url validation validator variable video web xml youtube





