| | |
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
| Thread Tools | Search this Thread |
apache api array basic beginner binary broken cache cakephp checkbox class cms code computing confirm cron curl customizableitems database date delete display dynamic echo email error external file files filter folder form forms forum function functions gc_maxlifetime google headmethod host howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction memmory memory menu mlm multiple mysql navigation oop parsing paypal pdf php phpmysql problem query question radio random recursion remote script search select server sessions sms snippet source space sql syntax system table thesishelp trouble tutorial update upload url validator variable video web youtube





