Changeset 174


Ignore:
Timestamp:
12/02/11 16:19:33 (13 years ago)
Author:
jkraaijeveld
Message:

.... and finally, fixed toSPSS to ensure the ordering stays correct if there are answers missing, something which can happen quite often.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/classes/Session.php

    r173 r174  
    6868                        return;
    6969               
     70                //Get the answers for all respondents
    7071                $answers = $this->getAnswers($headers);
    7172
     
    8283                        $entryString = "";
    8384                        //PHP doesn't automatically sort the indices so I have to do it myself
    84                         $keys = array_keys($entry);
    85                         asort($keys);
    8685                        //Entry elements can now be printed in order to match the headers
    87                         foreach($keys as $i)
     86                        for ($i = 0; $i < count($headers); $i++)
    8887                        {
    89                                 $entryString = $entryString . $entry[$i] . "\t";       
     88                                if(in_array($i, array_keys($entry)))
     89                                        $entryString = $entryString . $entry[$i] . "\t";       
     90                                else
     91                                        $entryString = $entryString . "\t";
    9092                        }
    9193                        fwrite($fileHandler, $entryString . "\n");     
     
    134136                                                $value = $value . $val . ",";
    135137                                        }
     138                                        //We all hate trailing commas
    136139                                        if (strlen($value) > 0) { $value = substr($value, 0, strlen($value)-1); }
    137140                                        $entry[$index] = $value;
Note: See TracChangeset for help on using the changeset viewer.