This topic is locked

export child records to excel

10/2/2010 3:28:06 PM
PHPRunner General questions
G
greener author

Hi,

I have a view that contains a field from a child table. I'd like to be able to export to an excel file and have the child records comma separated. Possible? thanks!
so 2 tables
animals

dog 1

cat 2
traits

best friend 1

friendly 1

proud 2

purrs 2
I want my excel file to look like
animal view

dog friendly,best friend

cat proud,purrs
thanks!

rg

J
jasonfrew 10/4/2010

id also like to be able to do something similar
i only require the export to be a .xls

A
ann 10/5/2010

Hi,
you can try to set up one of the fields as Custom on the View as settings dialog on the Visual Editor tab.

Here is a sample code:



$str = "";

$rstmp=CustomQuery("select Field1 from TableName where LinkField=".$data["LinkField"]);

while ($datatmp=db_fetch_array($rstmp))

$str.=$datatmp["Field1"].",";

$value = substr($str,0,-1);
G
greener author 10/12/2010



Hi,
you can try to set up one of the fields as Custom on the View as settings dialog on the Visual Editor tab.

Here is a sample code:



$str = "";

$rstmp=CustomQuery("select Field1 from TableName where LinkField=".$data["LinkField"]);

while ($datatmp=db_fetch_array($rstmp))

$str.=$datatmp["Field1"].",";

$value = substr($str,0,-1);




thanks Ann, that worked great. although just checked my actual example and the child table that is displaying (traits in my example) has a lookup table for the name (think it is a innerjoin ??) and unfortunately I cannot seem to get the query right. any help here would be greatly appreciated!
so to be specific I have three tables : "animal" , "animal-traits" , "trait_names"
table: animal

id name

1 dog

2 cat
animal-traits

aid tid

1 1

1 2

2 3

2 4

2 2
trait_name

id traitName

1 best friend

2 friendly

3 proud

4 purrs
I want my excel file to look like
animal view

dog friendly,best friend

cat proud,purrs,friendly
thank you very, very much!

A
ann 10/13/2010

Hi,
here is the code to try:

$str = "";

$rs1=CustomQuery("select tid from `animal-traits` where aid =".$data["id"]);

$data1=db_fetch_array($rs1);

$rstmp=CustomQuery("select traitName from `trait_name` where id =".$data1["tid"]);

while ($datatmp=db_fetch_array($rstmp))

$str.=$datatmp["Field1"].",";

$value = substr($str,0,-1);



If it doesn't help please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error. 'Demo Account' button can be found on the last screen in the program.