Stuck & Need Help with "Generate Report"

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!


Ok, I admit it, I bit off a bit more than I can chew.

I need to complete this "Generate Report" page for my employer and I'm
a little over my head.  I could use some additional assistance.  I say
additional because I've already had help which is greatly appreciated.
I do try to take the time and understand the provided script in hopes
on not having to trouble others on those.  But here it goes...

I need to allow the user to generate a report and thus have created a
file called generate_report.php.

I have a header.html and footer.html file so I'm just trying to fill
in the middle.

What I want to do is create a single file to display and process the

What I have is a set of records from three different groups.  I want
to allow the user to select what group's records he would like to
extract data from and what columns he wants displayed.  So, I have
basically two columns in the form: 1) what group(s) and 2) what

Now, the "what group(s)" column has a script to extract the list of
groups from a table of the same name and display it as a checkbox

The other column, "select columns" is a simple checkbox listing.

So, ideally, when the page is brought up for the first time, it'll
recognize the "submit" button hasn't been hit and will display the
form.  Once the user selects group(s) and column(s) and hits submit
(or in this case "Generate), the output would be a page with the
columns aligned horizontally and data underneath each header (just
like a spredsheet).

So, this is what I think I need:

1)  A script that will process the sel_groups and sel_cols arrays
(which has been provided but not tested); and

2) an echo statement that'll produce the desired output.

I'm going to fart around with it some more but would really appreciate
some help.

Oh, one question that just popped up (and I'll reseach it)...

can I have this page split PHP | HTML |PHP when using the "if
submitted" statement?  Seems like I would need to have just a single
php file so that if sumbitted, here is the query and output BUT if not
submitted, here is the form.  Hmmm...I need to think that one through
a bit more.




    // Begin the page now.
        $page_title = 'Generate Report';
        include ('./includes/header.html');

    //require_once ('includes/mysql_connect.php'); // Connect to
the db.

        // Check if the form has been submitted.
            if (isset($_POST['submitted'])) {

    require_once ('includes/mysql_connect.php'); // Connect to the

        // this script only build query
            switch ($_REQUEST['submit']){
                case "Generate":

        // first extract group
            $query = "";
            if(count($_REQUEST['sel_group']) > 0){
              $wval = array ();
              foreach($_REQUEST['sel_group'] as $k => $v){
            $wval[] = "groups_id=''";
          //extract the columns  
              $scols = array ();
              if(count($_REQUEST['sel_cols]']) > 0){
            foreach($_REQUEST['sel_group'] as $k => $v){
              $scols[] = "";
        //building query
            $where = join(' AND ', $wval);
            $sel_cols = join(',', $scols);
            $query = "SELECT FROM tasks WHERE


        //if $query is empty you can catch this case as an error
because there is not any group or selected columns


    //reset your form
//}  End of submit conditional.

//Output Form

// Always show the form.

} else { // Not a valid user ID.
    echo '<h1 id="mainhead">Page Error</h1>
    <p class="error">This page has been accessed in
error.</p><p><br /><br /></p>';

mysql_close(); // Close the database connection.

// End of links section.


<!--Create the form.-->
    <fieldset><legend>Generate Report</legend>

            <form action="handle_generate_report.php"

                <TABLE BORDER="1" cellpadding="5"
                        <TD rowspan="2"
valign="bottom"><strong>Select ICAO Group(s)</strong></TD>
colspan="2"><strong>Select Columns</strong></TD>
                        <TD><strong>ICAO Work
Programme</strong></TD><TD><strong>SME Input</strong></TD>
                        <TD align="left"
('includes/mysql_connect.php'); // Connect to the db.
                        $query = "SELECT *
FROM groups ORDER BY groups_id ASC";        
                        $result = @mysql_query
                        while($rows =
                           $id   =
$rows['groups_id'] ;
                       $name =

                           echo "<input
name=\"sel_group[]\" type=\"checkbox\" value=\"$id\">$name<BR>";
                <TD align="left" valign="top">
                    <input name="sel_cols"
type="checkbox" value="groups_name">ICAO Group Name<BR>
                    <input name="sel_cols"
type="checkbox" value="task_icaodesc">ICAO Description of Task<BR>
                    <input name="sel_cols"
type="checkbox" value="icaotask_id">ANC Task No.<BR>
                    <input name="sel_cols"
type="checkbox" value="task_compdate">Estimated Completion Date<BR>
                    <input name="sel_cols"
type="checkbox" value="task_icaosource">Source &amp; References<BR>
                    <input name="sel_cols"
type="checkbox" value="task_icaonote">ICAO Note on Progress<BR>
                <TD align="left" valign="top">
                    <input name="sel_cols"
type="checkbox" value="task_usposition">U.S. Position<BR>
                    <input name="sel_cols"
type="checkbox" value="task_exp_outcome">Expected Outcome<BR>
                    <input name="sel_cols"
type="checkbox" value="task_outcome">Outcome<BR>
                    <input name="sel_cols"
type="checkbox" value="task_usaction">U.S. Action<BR>
                    <input name="sel_cols"
type="checkbox" value="task_probs_issues">Problems &amp; Issues<BR>
                    <input name="sel_cols"
type="checkbox" value="task_smecomments">Notes/Comments<BR>

                    <input name="submit"
type="button" value="Generate">


<!-- End of Content -->


include ('includes/footer.html')

Site Timeline