Php 如何显示datename&;的记录;使用这种方法的年份

Php 如何显示datename&;的记录;使用这种方法的年份,php,mysql,select,where,Php,Mysql,Select,Where,此代码按月份和年份显示记录 例如: 2015年7月 2015年8月 2015年9月 这是我的代码,它正在工作 <?php $qry = "SELECT count(*), monthname(curdate), year(curdate) FROM cswd_records GROUP BY month(curdate), year(curdate)"; $run = mysql_query($qry) or die(mysql_error()); ?> <

此代码按月份和年份显示记录 例如:

  • 2015年7月
  • 2015年8月
  • 2015年9月
这是我的代码,它正在工作

<?php
  $qry = "SELECT count(*), monthname(curdate), year(curdate) FROM cswd_records GROUP BY month(curdate), year(curdate)";
   $run = mysql_query($qry) or die(mysql_error()); 
  ?>
</div>
<div class="col-md-3"></div>
<div class="col-md-6">
<Center><span class="impactsoc">Total Applicants by Month</span></center><br>
<table class="table table-striped table-bordered table-hover table-condensed" >
  <thead>
    <tr>
<th># of Applicants</th>
<th>Month</th>
    </tr>
  </thead>
  <tbody>       
    </tr>
    <?php while ($row = mysql_fetch_array($run)) {?>
        <tr>
        <td width="250"><h5><?php echo $row['count(*)']; ?></h5></td>
         <td width="250"><h5><a href="month.php?monthyear=<?php echo $row['monthname(curdate)'];?>-<?php echo $row['year(curdate)'];?>"><?php echo $row['monthname(curdate)'];?>&nbsp;&nbsp;<?php echo $row['year(curdate)'];?></h5></a> </td>
      </tr>
      <tr>
        <td colspan="2"><center><h4><i>Total Applicants:</i><font color="red"> <?php echo $row['count(*)']; ?></font></h4></center></td>
      </tr><?php }?>

</table>
如果只有1个值,则该值有效。如何同时显示月份和年份

$myr = $_GET['monthyear']; //getting the details by link(a href)
    $result = $db->prepare("SELECT * FROM cswd_records WHERE monthname(curdate)='". mysql_real_escape_string($myr) ."'");

你为什么不把年份也加上呢

$result = $db->prepare("SELECT * FROM cswd_records WHERE
monthname(curdate)='". mysql_real_escape_string($myr) ."' 
AND year(curdate)='". mysql_real_escape_string($myr) ."'");
编辑

使用

解决方案:

 $result = $db->prepare("SELECT * FROM cswd_records WHERE monthname(curdate) ='". mysql_real_escape_string($myr) ."' 
AND year(curdate)='". mysql_real_escape_string($myr1) ."'");

多亏了@Harshit Shrivastava

,这种方法肯定失去了使用预处理语句的好处,因为参数包含在sql中,而不是像它们应该的那样绑定为参数@kimdecastro,为什么要把
放在
之后呢。正如RamRaider所说,您应该使用正确的方式准备语句。用这种方式使用预先准备好的语句没有好处。它不起作用。请检查我的a HREF(link)2 echo行monthname&yearits woking现在我必须获取2变量。或者如果您使用的是同一个变量,那么我也发布了解决方案。
$myr = explode("-", $_GET['monthyear']);
$result = $db->prepare("SELECT * FROM cswd_records WHERE
monthname(curdate)='". mysql_real_escape_string($myr[0]) ."' 
AND year(curdate)='". mysql_real_escape_string($myr[1]) ."'");
 $result = $db->prepare("SELECT * FROM cswd_records WHERE monthname(curdate) ='". mysql_real_escape_string($myr) ."' 
AND year(curdate)='". mysql_real_escape_string($myr1) ."'");