By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,054 Members | 1,635 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,054 IT Pros & Developers. It's quick & easy.

Stuck & Need Help with "Generate Report"

P: n/a
Greetings.

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
form.

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
column(s).

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
list.

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.

Thanks.

Ward.

<?PHP

// 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
db.

// 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='{$v}'";
}

//extract the columns
$scols = array ();
if(count($_REQUEST['sel_cols]']) > 0){
foreach($_REQUEST['sel_group'] as $k => $v){
$scols[] = "{$v}";
}

//building query
$where = join(' AND ', $wval);
$sel_cols = join(',', $scols);
$query = "SELECT {$sel_cols} FROM tasks WHERE
{$where}";
}

}

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

break;

default:

//reset your form
unset($_REQUEST);
}
//} 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"
method="post">

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

while($rows =
mysql_fetch_array($result))
{
$id =
$rows['groups_id'] ;
$name =
$rows['groups_name'];

echo "<input
name=\"sel_group[]\" type=\"checkbox\" value=\"$id\">$name<BR>";
}
?>
</TD>
<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>
<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>
</TD>
</TR>

</TABLE></CENTER>

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

</form>

</fieldset>
<!-- End of Content -->
</td>
</tr>

</table>
<?php
include ('includes/footer.html')
?>
Feb 25 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.