1

This code, get a query from db and fill the template docx with that data, the only thing that is filled is not the data from the database, I already did output of the data i tried to insert and it seems fine, i guess i'm missing something in replacing the text, but i cant find where. Can someone help me?

require_once APPPATH.'PHPWord.php';
        //$i=0;
        // Create a new PHPWord Object
        $PHPWord = new PHPWord();
        //get query
        $queryResult = $this->get($id);
        //load template
        $document = $PHPWord->loadTemplate($queryResult[0]['template_location']);

        $document->setValue('weekday', date('l'));
        $document->setValue('time', date('H:i'));

        $result = mysql_query($queryResult[0]['query_sql']) or die (mysql_error());

        $i=1;

        while($row = mysql_fetch_row($result))
        {
            for($aux=0; $aux < mysql_num_fields($result); $aux++)
            {
                if(!isset($row[$aux]))  
                    $value = NULL;  
                elseif ($row[$aux] != "")  
                    $value = strip_tags($row[$aux]);
                else  
                    $value = "";

                $document->setValue($i, $value);
                echo $i,"=",$value, " ";
                $i++;
            }
        }

        $document->save('report.docx');

    }
NikiC
  • 100,734
  • 37
  • 191
  • 225
user3617397
  • 74
  • 1
  • 6
  • Please read https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Michas May 22 '15 at 10:09
  • thx for the update, but i dont have any problems with the data i receive, cause im echo everything i pass, and it is fine, i just have a problem, because document->setValue($i, $value); are not overwriten the places like it should be. but i try to take mysql_ and use pdo. – user3617397 May 22 '15 at 10:18

1 Answers1

1

the only you need is simple, almost everythin right just one thing missing, this:

$document->setValue(''.$i.'', $value);

and then it should work :)

Ricardo Origin
  • 175
  • 3
  • 14