Jump to content

Generate Report


snodrog742

Recommended Posts

Okay, I'm very new to PHP and my teacher is very unhelpful.  We are building a Generate Report page from Survey Responses that customers have submitted.  The page let's you pick an employee from a drop-down and then specify a Start Date and End Date to generate the report between.  The whole coding for this page is:

<?php require_once('../../../Connections/Evaluation_Admin.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_Evaluation_Admin, $Evaluation_Admin);
$query_Recordset1 = "SELECT * FROM Employee_Info";
$Recordset1 = mysql_query($query_Recordset1, $Evaluation_Admin) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);mysql_select_db($database_Evaluation_Admin, $Evaluation_Admin);
$query_Recordset1 = "SELECT * FROM Employee_Info ORDER BY Employee_Name ASC";
$Recordset1 = mysql_query($query_Recordset1, $Evaluation_Admin) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Client/Customer Listing</title>
<link href="http://www.wiu.edu/users/ac118/419Spr2010/evaluation/admin/styles.css" rel="stylesheet" type="text/css" /><!--[if IE 5]>
<style type="text/css"> 
/* place css box model fixes for IE 5* in this conditional comment */
.twoColFixLt #sidebar1 { width: 230px; }
</style>
<![endif]--><!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.twoColFixLt #sidebar1 { padding-top: 30px; }
.twoColFixLt #mainContent { zoom: 1; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
</head>

<body class="twoColFixLt">
<script type='Text/JavaScript' src='scw.js'></script>

<div id="container">
  <div id="sidebar1">
    <h3>Navigation</h3>
    <p><?php include('../nav.inc'); ?> </p>
  <!-- end #sidebar1 --></div>
  <div id="mainContent">
    <h1> Generate a Report<!-- end #mainContent -->
    </h1>
    <form id="form1" name="form1" method="post" action="results.php">
      <p>Employee:
        <select name="employee" id="employee">
          <?php
do {  
?>
          <option value="<?php echo $row_Recordset1['id']?>"><?php echo $row_Recordset1['Employee_Name']?></option>
          <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  $rows = mysql_num_rows($Recordset1);
  if($rows > 0) {
      mysql_data_seek($Recordset1, 0);
  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  }
?>
        </select>
        <br />
        Start Date: <input  id='start_date' type='text' tabindex='130' value='' /><img

                                    src='scw.gif'

                                    title='Click Here' alt='Click Here'

                                    onclick="scwShow(scwID('start_date'),event);" /><br />
        End Date: 
        <input  id='end_date' type='text' tabindex='130' value='' /><img

                                    src='scw.gif'

                                    title='Click Here' alt='Click Here'

                                    onclick="scwShow(scwID('end_date'),event);" />
        <input type="submit" name="button" id="button" value="Submit" />
      </p>
    </form>
    <p> </p>
</div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
<!-- end #container --></div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

 

On the report we want it to show the Employee Name, and an Average of the Survey Responses.  This is where I have no idea where to start.  So far I have

<?php require_once('../../../Connections/Evaluation_Admin.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_Recordset1 = "-1";
if (isset($_POST['employee'])) {
  $colname_Recordset1 = $_POST['employee'];
}
mysql_select_db($database_Evaluation_Admin, $Evaluation_Admin);
$query_Recordset1 = sprintf("SELECT Who_being_reviewed FROM Survey_Responses WHERE Who_being_reviewed = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $Evaluation_Admin) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$colname_Recordset2 = "-1";
if (isset($_POST['id'])) {
  $colname_Recordset2 = $_POST['id'];
}
mysql_select_db($database_Evaluation_Admin, $Evaluation_Admin);
$query_Recordset2 = sprintf("SELECT * FROM Employee_Info WHERE id = %s", GetSQLValueString($colname_Recordset2, "int"));
$Recordset2 = mysql_query($query_Recordset2, $Evaluation_Admin) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Client/Customer Listing</title>
<link href="http://www.wiu.edu/users/ac118/419Spr2010/evaluation/admin/styles.css" rel="stylesheet" type="text/css" /><!--[if IE 5]>
<style type="text/css"> 
/* place css box model fixes for IE 5* in this conditional comment */
.twoColFixLt #sidebar1 { width: 230px; }
</style>
<![endif]--><!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.twoColFixLt #sidebar1 { padding-top: 30px; }
.twoColFixLt #mainContent { zoom: 1; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
</head>

<body class="twoColFixLt">
<script type='Text/JavaScript' src='scw.js'></script>

<div id="container">
  <div id="sidebar1">
    <h3>Navigation</h3>
    <p><?php include('../nav.inc'); ?> </p>
  <!-- end #sidebar1 --></div>
  <div id="mainContent">
    <h1>  Report<!-- end #mainContent -->
    </h1>
    <form id="form1" name="form1" method="get" action="">
      <p><?php echo $row_Recordset1['id']; ?><?php echo $row_Recordset2['Employee_Name']; ?><?php echo $row_Recordset1['Who_being_reviewed']; ?></p>
    </form>
    <p> </p>
</div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
<!-- end #container --></div>
</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);
?>

 

This is only showing me the ID number of the employee so far.  Let me know if you need any more info or something clarified.  I'll do the best that I can.  Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/199870-generate-report/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.