How can I make Template.doc Variables..... Variable

Oct 8, 2012 at 11:14 PM

I amworking on similar thing as the Template.dox example but instead of having 10 planets, I have over 2000 entries from Database. So here is the Example:

<!--p
require_once '../PHPWord.php';

$PHPWord = new PHPWord();

$document = $PHPWor-->loadTemplate('Template.docx');

$document->setValue('Value1', 'Sun');
$document->setValue('Value2', 'Mercury');
$document->setValue('Value3', 'Venus');
$document->setValue('Value4', 'Earth');
$document->setValue('Value5', 'Mars');
$document->setValue('Value6', 'Jupiter');
$document->setValue('Value7', 'Saturn');
$document->setValue('Value8', 'Uranus');
$document->setValue('Value9', 'Neptun');
$document->setValue('Value10', 'Pluto');

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

$document->save('Solarsystem.docx');
?>

I am trying to use something like this:

<!--p

$host = "MyServer"; 
$user = "MyUsername"; 
$pass = "MyPassword"; 
$database = "MyDatabase"; 

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
mysql_select_db($database, $linkID) or die("Could not find database."); 

$query = "SELECT * FROM EXM_Written WHERE Slectt='2012' ORDER BY Sort_En";
$resultIF = mysql_query($query, $linkID) or die("Data not found."); 
$rbw = mysql_fetch_assoc($resultIF); 




require_once 'PHPWord.php';

$PHPWord = new PHPWord();

$document = $PHPWor-->loadTemplate('Template.docx');

for($x = 0 ; $x < mysql_num_rows($resultIF) ; $x++)
	{
	$document->setValue('$x', $rbw['Quest_En']);
	$document->setValue('Value3', $rbw['AnsA_En']);
	$document->setValue('Value4', $rbw['AnsB_En']);
	$document->setValue('Value5', $rbw['AnsC_En']);
	$document->setValue('Value6', $rbw['AnsD_En']);
	
	}

$document->setValue('Value8', 'Uranus');
$document->setValue('Value9', 'Neptun');
$document->setValue('Value10', 'Pluto');

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

$document->save(Solarsystem.docx');
?>

I have no problem getting the Data, what isnt working is I'd like to replace 'Value2' by $x which is a number from 0 to the number of entries.

On the Template.doc file, I replace

${Value1} for ${1} but it doesnt work.

Is there something I should do to have automatic variable creation from 0 to 2000 instead of listing in my php file all 2000 lines?

Thanks!