Operating System - Linux
1748150 Members
3516 Online
108758 Solutions
New Discussion юеВ

generating report using php

 
Sasirekha
Occasional Contributor

generating report using php

Hi ,

Please give me some idea how to generate reports using php.
The query given to db is dynamic.i.e, the user may need any report which may not be excepted.

Thanks in advance
Hope I might get an idea for this from the group
3 REPLIES 3
Rajeev  Shukla
Honored Contributor

Re: generating report using php

You will have to make your first page which will give the user a set of reports you can run and post the form to another PHP program. Which will then run different SQL statements depending on the query user has selected and display it in anyway you like.

Let me know if you need more details about doing it

Sasirekha
Occasional Contributor

Re: generating report using php

Hi Rajeev,

Your idea is ok ,but I am struck up in ,how to generate different queries automatically with out hardcoding it?

Thanks
Rekha
William E Howard
Regular Advisor

Re: generating report using php

Sasirekha, its been a while since I've done any advanced SQL queries or worked with PHP, so I can't tell you the exact syntax, but there are numerous ways this can be pulled off and I can at least describe it in a logical method.

Remember your SQL query is basically just a string, and the easiest way to assemble it is using a string variable. I have seen a dynamic reporting system that uses a front loader screen where you check all the fields you want reported, then hit submit.

One example: Setup a front form page, with a dropdown to select which SQL table you want to query. That refreshes the screen and brings up a list of check boxes, one to represent each field in that table. You can also have a radio button or a dropdown, however you want to handle it, to deal with the SORT feature, as well as a text box next to each field's check box for a text match.

Using the GET or POST, gather the data submitted. Say Last Name, Department, Phone Number and Address were checked from the Table named Directory, and you put "David" in the text box at Last Name

Each of those check boxes would represent a single field in the SQL database.

If you are any good at string manipulation, it should be fairly simple to convert all that data into one long string, where your end result is

"select Last_Name Departmet Phone_Number from Directory where Last_Name='David'"

If this is for technical users who may actually be able to handle SQL queries, you can even have this data refreshed in real time into a text box, so if the user wants to make a small change that isn't anticipated by your form, they can do it directly. All that would be passed is that text box in the end. Even for the non technical users, this would be the method I recommend because you pass less data thru the form's POST. Just set the text box to hidden for non technical users.

What you plan on doing may be vastly different from this, but the underlying concept is generally the same. Use string manipulation / general variable manipulation to convert the form data into a workable SQL query.

You can also implement security on this, such as only members of HR can access the Directory table, and only Admins can see the SSN field, but it requires more work on both the PHP scripting and SQL server side.

Hope this helps, if you have any questions just post and I'm sure someone can answer them.