kabucek Posted October 30, 2008 Share Posted October 30, 2008 Hi @LL I want export table in php to excell file. Here is for example link: https://mydomain.local/something.php?operation=hyperlinknametosomething2.php&table1.field1=111&table1.field2=123&table1.field3 and this display 5 fields with maximum of 10 rows. Is there a way to export to excel file using above link? Our framework use sql & php. It would be great if this could be a hyperlink with text: "click to save" or a button? if need more info let me know. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/ Share on other sites More sharing options...
Mchl Posted October 30, 2008 Share Posted October 30, 2008 Easiest method is to export your data as a CSV file, which can be loaded into Excel and other spreadsheet programs. CSV stands for 'comma spaced variables' because it contains your data, delimited with commas (usually) like this row#,field1,field2,field3 "1","value1","value2","value3" Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678575 Share on other sites More sharing options...
Maq Posted October 30, 2008 Share Posted October 30, 2008 Here is a sample of how to open and write to a CSV file: $myFile = "your_list.csv"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $field1 . ", " . $field2 . ", " . $field3 . "\n"); Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678580 Share on other sites More sharing options...
Maq Posted October 30, 2008 Share Posted October 30, 2008 CSV stands for 'comma spaced variables' because it contains your data, delimited with commas (usually) like this Actually, CSV stands for 'comma-separated values'. Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678585 Share on other sites More sharing options...
Mchl Posted October 30, 2008 Share Posted October 30, 2008 Actually, CSV stands for 'comma-separated values'. Makes more sense... I'm not native to English so I confuse TLAs from time to time. You know that SQL is for Standardised Questioning Language? Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678589 Share on other sites More sharing options...
kabucek Posted October 30, 2008 Author Share Posted October 30, 2008 Here is a sample of how to open and write to a CSV file: $myFile = "your_list.csv"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $field1 . ", " . $field2 . ", " . $field3 . "\n"); but I don't want to specify fields. I need to use the link above Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678592 Share on other sites More sharing options...
kabucek Posted October 30, 2008 Author Share Posted October 30, 2008 this is is actually a query to sql database. if this helps. thanks Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678595 Share on other sites More sharing options...
Maq Posted October 30, 2008 Share Posted October 30, 2008 Here is a sample of how to open and write to a CSV file: $myFile = "your_list.csv"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $field1 . ", " . $field2 . ", " . $field3 . "\n"); but I don't want to specify fields. I need to use the link above Can you explain exactly what you're trying to accomplish? My guess is that you're taking the fields from the URL and using them to query something from your database. Then place the results from that query in the CSV file...? Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678597 Share on other sites More sharing options...
Mchl Posted October 30, 2008 Share Posted October 30, 2008 I'm not sure I understand... Is this a link to some application, that you cannot modify? Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678602 Share on other sites More sharing options...
Maq Posted October 30, 2008 Share Posted October 30, 2008 Actually, CSV stands for 'comma-separated values'. Makes more sense... I'm not native to English so I confuse TLAs from time to time. You know that SQL is for Standardised Questioning Language? SQL does not stand for that, it stands for 'Structured Query Language'. Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678603 Share on other sites More sharing options...
Mchl Posted October 30, 2008 Share Posted October 30, 2008 Aw! You caught me again Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678606 Share on other sites More sharing options...
kabucek Posted October 30, 2008 Author Share Posted October 30, 2008 yes, link above gives a small table of listing from our database. I want to export that listing to excel file using this link if possible. I know that I can use queries and manually typing fields but this is too much hassle. is there a way that we can use "header" function to or something better to export everything that this link displays? https://mydomain.local/something.php?operation=hyperlinknametosomething2.php&table1.field1=111&table1.field2=123&table1.field3 thanks Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678609 Share on other sites More sharing options...
Maq Posted October 30, 2008 Share Posted October 30, 2008 You would have to use get_contents or cURL to get the information from that page. This makes things a little more complicated... Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678612 Share on other sites More sharing options...
Mchl Posted October 30, 2008 Share Posted October 30, 2008 Nice idea. Didn't think of that. Quote Link to comment https://forums.phpfreaks.com/topic/130752-export-table-to-excel-in-php/#findComment-678615 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.