Forum


Replies: 2   Views: 3428
Table template array generation error
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by techno77  · 02-09-2013 - 10:53

Hello, dear friends.



Try to genereta table from table template. But some strange error, that I can't sove in 2 days.



THIS CODE WORKS FINE

====

$settings = array(

    'header' => true

);

$docx->addTemplateVariable(

    array(

        array(

            'TNUM' => 'Product A',

            'TNAME' => '10',

            'TPRICE' => '5',

            'TEDIZ' => '5',

            'TCOUNT' => '5',

            'TSUMMA' => '5'

        ),

        array(

            'TNUM' => 'Product B',

            'TNAME' => '10',

            'TPRICE' => '5',

            'TEDIZ' => '5',

            'TCOUNT' => '5',

            'TSUMMA' => '5'

        ),

        array(

            'TNUM' => 'Product C',

            'TNAME' => '10',

            'TPRICE' => '5',

            'TEDIZ' => '5',

            'TCOUNT' => '5',

            'TSUMMA' => '5'

        ),

    ),

    'table',

    $settings

);

$docx->addTemplateVariable($table,'table',$settings);    

====



THIS CODE DOESN'T WORKS

====

$settings = array(

    'header' => true

);

$table = array();

$query = "SELECT * FROM `table`";

$sql = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($sql) > 0){

    $i = 1;

    while ($row = mysql_fetch_array($sql)) :

        $table[] = array(

        'TNUM' => $i,

        'TNAME' => $row["name"],

        'TPRICE' => $row["price"],

        'TEDIZ' => $row["edizm"],

        'TCOUNT' => $row["count"],

        'TSUMMA' => $row["total"]

        );

        $i++; 

    endwhile;

}

$docx->addTemplateVariable($table,'table',$settings);

====



How to correct gererate arrays to table tamplate?