本人做了一个工资的系统,插入自定义的扣款项目后,但是每次查询,都有一个扣款项目显示不出来,如下是查询页面的代码,附件是查询页面的图,请各位大虾帮助一下,谢谢了!由于发不了那么多的代码,我把代码放在了以下的附件(1.TXT)下,谢谢

解决方案 »

  1.   

    <?php
    //initialize the session
    session_start();// ** Logout the current user. **
    $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
    if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
      $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
    }if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
      //to fully log out a visitor we need to clear the session varialbles
      session_unregister('MM_Username');
      session_unregister('MM_UserGroup');
      session_unregister('MM_UserType');
      $logoutGoTo = "index.php";
      if ($logoutGoTo) {
        header("Location: $logoutGoTo");
        exit;
      }
    }
    ?>
    <?php
    session_start();
    $MM_authorizedUsers = "";
    $MM_donotCheckaccess = "true";// *** Restrict Access To Page: Grant or deny access to this page
    function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
      // For security, start by assuming the visitor is NOT authorized. 
      $isValid = False;   // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
      // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
      if (!empty($UserName)) { 
        // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
        // Parse the strings into arrays. 
        $arrUsers = Explode(",", $strUsers); 
        $arrGroups = Explode(",", $strGroups); 
        if (in_array($UserName, $arrUsers)) { 
          $isValid = true; 
        } 
        // Or, you may restrict access to only certain users based on their username. 
        if (in_array($UserGroup, $arrGroups)) { 
          $isValid = true; 
        } 
        if (($strUsers == "") && true) { 
          $isValid = true; 
        } 
      } 
      return $isValid; 
    }$MM_restrictGoTo = "index.php";
    if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
      $MM_qsChar = "?";
      $MM_referrer = $_SERVER['PHP_SELF'];
      if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
      if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
      $MM_referrer .= "?" . $QUERY_STRING;
      $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
      header("Location: ". $MM_restrictGoTo); 
      exit;
    }
    ?>
    <?php require_once('Connections/salary.php'); ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <link href="include/style.css" rel="stylesheet" type="text/css">
    <?php
    session_start();
    $colname_Recordset1='@#';
    if (isset($_SESSION['MM_Username'])) {
      $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
    }
    if($_SESSION['MM_UserType']=='user'){
      if(isset($_POST['monthfield'])){
        $query_Recordset1 = sprintf("SELECT * FROM salary%s WHERE StaffId = '%s'", $_POST['monthfield'], $colname_Recordset1);
        $query_Recordset2 = sprintf("SELECT * FROM fieldname WHERE YearMonth = '%s' and type='1' and salarytype='0' ORDER BY 'id' ASC", $_POST['monthfield']);
        $query_Recordset3 = sprintf("SELECT * FROM fieldname WHERE YearMonth = '%s' and type='0' and salarytype='0' ORDER BY 'id' ASC", $_POST['monthfield']);
      }
      else{
        $query_Recordset1 = sprintf("SELECT * FROM salary%s WHERE StaffId = '%s'", $_GET['id'], $colname_Recordset1);
        $query_Recordset2 = sprintf("SELECT * FROM fieldname WHERE YearMonth = '%s' and type='1' and salarytype='0' ORDER BY 'id' ASC",$_GET['id']);
        $query_Recordset3 = sprintf("SELECT * FROM fieldname WHERE YearMonth = '%s' and type='0' and salarytype='0' ORDER BY 'id' ASC",$_GET['id']);
      }
    }
    elseif($_SESSION['MM_UserType']=='temp'){
      if(isset($_POST['monthfield'])){
        $query_Recordset1 = sprintf("SELECT * FROM salarytemp%s WHERE StaffId = '%s'", $_POST['monthfield'], $colname_Recordset1);
        $query_Recordset2 = sprintf("SELECT * FROM fieldname WHERE YearMonth = '%s' and type='1' and salarytype='1' ORDER BY 'id' ASC", $_POST['monthfield']);
        $query_Recordset3 = sprintf("SELECT * FROM fieldname WHERE YearMonth = '%s' and type='0' and salarytype='1' ORDER BY 'id' ASC", $_POST['monthfield']);
      }
      else{
        $query_Recordset1 = sprintf("SELECT * FROM salarytemp%s WHERE StaffId = '%s'", $_GET['id'], $colname_Recordset1);
        $query_Recordset2 = sprintf("SELECT * FROM fieldname WHERE YearMonth = '%s' and type='1' and salarytype='1' ORDER BY 'id' ASC",$_GET['id']);
        $query_Recordset3 = sprintf("SELECT * FROM fieldname WHERE YearMonth = '%s' and type='0' and salarytype='1' ORDER BY 'id' ASC",$_GET['id']);
      }
    }
    mysql_query("use staffsalary") or die(mysql_error());
    $Recordset1 = mysql_query($query_Recordset1, $salary);
    $Recordset2 = mysql_query($query_Recordset2, $salary);
    $Recordset3 = mysql_query($query_Recordset3, $salary);
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $row_Recordset2 = mysql_fetch_assoc($Recordset2);
    $row_Recordset3 = mysql_fetch_assoc($Recordset3);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    $totalRows_Recordset2 = mysql_num_rows($Recordset2);
    $totalRows_Recordset3 = mysql_num_rows($Recordset3);
    $totalNum = $totalRows_Recordset2+$totalRows_Recordset3;
    if ($totalRows_Recordset1==0 or mysql_error() ){
        echo "<script language='JavaScript'>alert('很抱歉,暂时查找不到该月工资');location.href='search.php';</script>";
    }
    ?>
    </head>
    <body>
    <table width="800" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="2" background="pictures/dl_t_a1.gif"><img src="pictures/dl_t_a.gif" width="778" height="83"></td>
      </tr>
      <tr>
        <td width="175" valign="top"><TABLE width=175 border=0 cellPadding=0 cellSpacing=0 
    background=pictures/dl_t_d.gif>
          <TBODY>
            <TR>
              <TD>
                <DIV align=right></DIV></TD>
            </TR>
            <TR>
              <TD>&nbsp;</TD>
            </TR>
            <TR>
              <TD vAlign=top height=214>
                <TABLE cellSpacing=0 cellPadding=0 width="91%" align=right border=0>
                  <TBODY>
                    <TR>
                      <TD width=12>&nbsp;</TD>
                      <TD width=154 background=pictures/yg.jpg 
              height=32>&nbsp;</TD>
                    </TR>
                    <TR>
                      <TD width=12 height=80>&nbsp;</TD>
                      <TD width=154 height=80 background=pictures/p_t_3.gif>
                        <TABLE width="100%" border=0>
                          <TBODY>
                            <TR>
                              <TD width="14%" height=16>&nbsp;</TD>
                              <TD width="13%" height=16><IMG height=18 
                      src="pictures/jwgl_button1.gif" width=13></TD>
                              <TD width="73%"><A class=font2 
                      href="search.php" 
                      target=_self>工 资 查 询 </A></TD>
                            </TR>
                            <TR>
                              <TD width="14%" height=19>&nbsp;</TD>
                              <TD width="13%" height=19><IMG height=18 
                      src="pictures/jwgl_button1.gif" width=13></TD>
                              <TD width="73%" height=19><A class=font2 
                      href="<?php echo $logoutAction ?>" 
                      target=_self>注 销 用 户</A></TD>
                            </TR>
                          </TBODY>
                      </TABLE></TD>
                    </TR>
                    <TR>
                      <TD width=12>&nbsp;</TD>
                      <TD width=154 background=pictures/p_t_4.gif 
              height=15>&nbsp;</TD>
                    </TR>
                  </TBODY>
              </TABLE></TD>
            </TR>
            <TR>
      

  2.   

    <TD>&nbsp;</TD>
            </TR>
            <TR>
              <TD height=192>&nbsp;</TD>
            </TR>
          </TBODY>
        </TABLE></td>
        <td width="625">
      <table width="90%"  border="0" align="center" cellpadding="3" cellspacing="1">
            <tr>
              <td colspan="2"><span class="font4"></span><span class="font4"><strong><?php echo $_POST['monthfield'].$_GET['id']; ?></strong></span>工资单(单位:元)</td>
            </tr>
            <tr>
              <td colspan="2"><hr size="1"></td>
            </tr>
            <tr valign="top">
              <td><table width="95%"  border="0" align="center" cellpadding="3" cellspacing="1">
              <?php
          $i=1;
      if($_SESSION['MM_UserType']=='user'){
    while($i<=($totalRows_Recordset2+6)){
      if (($i==1) and ($row_Recordset1['Post']<>0)){
          echo "<tr><td width=145>岗位</td><td width=146>".$row_Recordset1['Post']."</td></tr>";
      }
      elseif (($i==2) and ($row_Recordset1['WageForSeniortity']<>0)){
          echo "<tr><td width=145>工龄</td><td>".$row_Recordset1['WageForSeniortity']."</td></tr>";   
      }
      elseif (($i==3) and ($row_Recordset1['Allowance']<>0)){
          echo "<tr><td width=145>补贴</td><td width=146>".$row_Recordset1['Allowance']."</td></tr>";   
      }
      elseif (($i==4) and ($row_Recordset1['GasPay']<>0)){
          echo "<tr><td width=145>煤补</td><td width=146>".$row_Recordset1['GasPay']."</td></tr>";   
      }
      elseif (($i==5) and ($row_Recordset1['WaterAndElectricity']<>0)){
          echo "<tr><td>水电补</td><td width=146>".$row_Recordset1['WaterAndElectricity']."</td></tr>";   
      }
      elseif (($i==6) and ($row_Recordset1['LadyAllowance']<>0)){
          echo "<tr><td width=145>女工卫生保护补贴</td><td width=146>".$row_Recordset1['LadyAllowance']."</td></tr>";   
      }
      elseif ($i>6){
          $name=sprintf("field%d",$i-6);
      if ($row_Recordset1[$name]<>0){
          echo "<tr><td width=145>".$row_Recordset2['name']."</td><td width=146>".$row_Recordset1[$name]."</td></tr>";     
      }
      if($row_Recordset2['name']=="应发数" and $row_Recordset1[$name]<>0){
      break;            
      }
      $row_Recordset2=mysql_fetch_assoc($Recordset2);   
      }
      $i++;
    }
    $j=$i-5;
      }
      elseif($_SESSION['MM_UserType']=='temp'){
       while($i<=($totalRows_Recordset2+5)){
      if (($i==1) and ($row_Recordset1['Post']<>0)){
          echo "<tr><td width=145>岗位工资</td><td width=146>".$row_Recordset1['Post']."</td></tr>";
      }
      elseif (($i==2) and ($row_Recordset1['Performance']<>0)){
          echo "<tr><td width=145>绩效工资</td><td>".$row_Recordset1['Performance']."</td></tr>";   
      }
      elseif (($i==3) and ($row_Recordset1['SkillAllowance']<>0)){
          echo "<tr><td width=145>技能班长补贴</td><td width=146>".$row_Recordset1['SkillAllowance']."</td></tr>";   
      }
      elseif (($i==4) and ($row_Recordset1['LadyAllowance']<>0)){
          echo "<tr><td width=145>女工卫生保护补贴</td><td width=146>".$row_Recordset1['LadyAllowance']."</td></tr>";   
      }
      elseif (($i==5) and ($row_Recordset1['NightTariff']<>0)){
          echo "<tr><td width=145>夜班费</td><td width=146>".$row_Recordset1['NightTariff']."</td></tr>";   
      }
      elseif ($i>5){
          $name=sprintf("field%d",$i-5);
      if ($row_Recordset1[$name]<>0){
          echo "<tr><td width=145>".$row_Recordset2['name']."</td><td width=146>".$row_Recordset1[$name]."</td></tr>";     
      }
      if($row_Recordset2['name']=="应发数" and $row_Recordset1[$name]<>0){
     break;            
      }
      $row_Recordset2=mysql_fetch_assoc($Recordset2);   
      }
      $i++;
    }
    $j=$i-4;
      }
    ?>
              </table></td>
              <td><table width="95%" border="0" align="center" cellpadding="3"  cellspacing="1">
                <?php
    $num=$totalNum;
            /*if($_SESSION['MM_UserType']=='user'){
      $num=$totalNum-2;
    }
    elseif($_SESSION['MM_UserType']=='temp'){
      $num=$totalNum-1;
    }*/
    while($j<=$num){
       $name=sprintf("field%d",$j);
       if ($row_Recordset1[$name]<>0){
      echo "<tr><td width=145>".$row_Recordset3['name']."</td><td width=146>".$row_Recordset1[$name]."</td></tr>";     
        }
    if($row_Recordset3['name']=="应扣数"){
      break;
    }  
      $j++;
          $row_Recordset3=mysql_fetch_assoc($Recordset3); 
    }
    ?>
              </table></td>
            </tr>
            <tr>
              <td colspan="2"><hr size="1"></td>
            </tr>
            <tr>
              <td colspan="2">
      <?php 
      $row_Recordset2=mysql_fetch_assoc($Recordset2); 
      $row_Recordset3=mysql_fetch_assoc($Recordset3); 
      if($_SESSION['MM_UserType']=='user'){
        $name=sprintf("field%d",$j+1);
          echo $row_Recordset2['name'].":".$row_Recordset1[$name]."    ";
    $name=sprintf("field%d",$j+2);
                if($row_Recordset1[$name]<>0){
          echo $row_Recordset3['name'].":".$row_Recordset1[$name]."    ";;
        }
    if(($j+3)==$totalNum){
      $name=sprintf("field%d",$totalNum);
      $row_Recordset2=mysql_fetch_assoc($Recordset2); 
      echo $row_Recordset2['name'].":".$row_Recordset1[$name]."  ";
    }
    else{
      $b=0;
      for($t=$j+3;$t<=$totalNum;$t++){
        $name=sprintf("field%d",$t);
        $row_Recordset2=mysql_fetch_assoc($Recordset2); 
        if($row_Recordset1[$name]<>0){
      if($b%3==0){
        echo "<p>";
      }
          echo $row_Recordset2['name'].":".$row_Recordset1[$name]."    ";
        }
       $b++; 
      }
    }
      }
      elseif($_SESSION['MM_UserType']=='temp'){
        $name=sprintf("field%d",$j+1);
        if($row_Recordset1[$name]<>0){
          echo $row_Recordset2['name'].":".$row_Recordset1[$name];
        }
      }   
      ?></td>
            </tr>
          </table>
      <br>
        </td>
      </tr>
      <tr>
        <td colspan="2"><HR align=center width=800 noShade SIZE=1></td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>