用get来检索php中的值

时间:2015-07-27 12:12:11

标签: php mysql

我想使用GET函数从表中检索信息。但它不起作用。拜托,我做错了什么?



  <td><?php echo $row['count(*)']; ?></td>
        <td>N<?php echo number_format($row['sum(basic)'],2); ?></td>
        <td>N<?php echo number_format($row['sum(hmo)'],2); ?></td>
        <td>N<?php echo number_format($row['sum(dha)'],2); ?></td>
        <td>N<?php echo number_format($row['sum(tax)'],2); ?></td>
        <td>N<?php echo number_format($row['sum(netpay)'],2); ?></td>
        <td><a href="view_payroll_month.php?month=<?php echo $row['year(date)'];?>"><?php echo $row['year(date)'];?></a> </td>
     	</tr><?php }?>
&#13;
&#13;
&#13;

第二页我希望结果显示在

&#13;
&#13;
$year = $_GET['year'];


$qry = "SELECT count(*), sum(basic), sum(hmo), sum(pension), sum(dha), sum(tax), sum(netpay), month(date) FROM salary WHERE year(date) ='$year' GROUP BY month(date)";
$run = mysql_query($qry) or die(mysql_error());


<?php while ($row = mysql_fetch_array($run)) {?>

 
  <tr>
        <td><?php echo $row['count(*)']; ?></td>
        <td>N<?php echo number_format($row['sum(basic)'],2); ?></td>
        <td>N<?php echo number_format($row['sum(hmo)'],2); ?></td>
        <td>N<?php echo number_format($row['sum(dha)'],2); ?></td>
        <td>N<?php echo number_format($row['sum(tax)'],2); ?></td>
        <td>N<?php echo number_format($row['sum(netpay)'],2); ?></td>
        <td><a href="view_month.php?month=<?php echo $row['month(date)'];?>"><?php echo $row['month(date)'];?></a> </td>
     	</tr><?php }?>
                                    
                            
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

这样可行。

<td><?php echo $row['count(*)']; ?></td>
        <td>N<?php echo number_format($row['sum(basic)'],2); ?></td>
        <td>N<?php echo number_format($row['sum(hmo)'],2); ?></td>
        <td>N<?php echo number_format($row['sum(dha)'],2); ?></td>
        <td>N<?php echo number_format($row['sum(tax)'],2); ?></td>
        <td>N<?php echo number_format($row['sum(netpay)'],2); ?></td>
        <td><a href="view_payroll_month.php?year=<?php echo $row['year(date)'];?>">><?php echo $row['year(date)'];?></a> </td>
        </tr><?php }?>

原因:您曾尝试在href内传递值。并尝试从获取年份参数检索。只需在href内每月更改一次。你现在可以找回一年了。 name参数必须等于获取name参数。

答案 1 :(得分:0)

这是您链接中的网址:

view_payroll_month.php?month=...

查询字符串参数名为month。但是您尝试获取名为year的值:

$_GET['year']

查询字符串和/或表单值是键/值对。这些值由与它们关联的键(名称)唯一标识。所以你需要:

  • month而不是year
  • 获取值
  • 传递值year而不是month
  • 除了year之外,还传递值month

这样的事情:

<a href="view_payroll_month.php?month=<?php echo $row['month(date)']; ?>&year=<?php echo $row['year(date)']; ?>">