mp1234 Posted March 23, 2009 Share Posted March 23, 2009 hi, I am in need of help again!!! In quick terms, I am using mssql queries to populate a webpage. The result is two numbers displayed on the page. My question comes in when I want to do: 1. make the result a link to another webpage/pop up excel - no idea how to go about doin that 2. link is just another query that returns different output to excel - don't know this also... for example: query is total number of employees in new york. it returns 5 employees. when the number is clicked it opens xls with Title: empl and names of the employees... query2 is total number of employees in new york but specific city. it returns 2 and again when clicked on number it opens xls with names of the emps... I tried doing following but of course lot of mistakes...and long way to go <? php /*DB connections*/ /*get number of emps in same state $queryEmp = "select count(empCat) as IE from employee where state = 'NY'"; $export=mssql_query($queryEmp); $queryEmp2 = "select count(empCity) as cnt from EMPProfile where state = 'NY' and city = 'something' "; $export=mssql_query($queryEmp); $queryEmp3 = "select empno, empname from employee where state = 'NY'"; $export=mssql_query($queryEmp); $fields = mysql_num_fields($export); $queryEmp4 = "select empno, empname from employee where state = 'NY' and city = 'something' "; $export=mssql_query($queryEmp); $fields2 = mysql_num_fields($export); ?> <TR> <TD colspan=1> State <BR></TD> <!-- populates number on webpage --> <TD> <?php echo $queryEmp ;?> </TD> <\TR> <TR> <TD colspan=2> City <BR></TD> <!--populates 2nd number on webpage --> <TD> <?php echo $queryEmp2 ;?> </TD> <\TR> And then I get lost: I have checked many php and excel code examples....many use mysql and some of them are freeware/shareware...i didn't want anything too complicated....just simple as stated above while learning from my peers like always....any help is greatly appreciated... Thanks mp Link to comment https://forums.phpfreaks.com/topic/150777-excel-from-php/ Share on other sites More sharing options...
Mark Baker Posted March 23, 2009 Share Posted March 23, 2009 To start with, you need to be consistent with the database that you're querying: MS SQL Server or MySQL.... your code snippet seems to mix and match. e.g. $export=mssql_query($queryEmp); $fields2 = mysql_num_fields($export); When you output the table for your first page with the two values, make each one an HTML link to a script that will retrieve the additional data that you want. Write the linked script(s) to retrieve the data that you need. Extract that data and format it as you want, either using a PHP Excel library such as PHPExcel, or as a comma-separated value or similar. To send something to the browser so that it will open in Excel, you need to send the http headers to indicate that it is an Excel file rather than the default headers for an HTML file Link to comment https://forums.phpfreaks.com/topic/150777-excel-from-php/#findComment-792176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.