此代码按月和年显示记录 例如:
这里我的代码正常运作。
<?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)'];?> <?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>
这是我的问题。如何显示2015年7月的所有列表
(如果我只想显示月份或年份,它就可以工作。我不知道它的2值。)
网址价值:
month.php?monthyear=August-2015
如果只有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) ."'");
答案 0 :(得分:0)
为什么不把年份放在
$result = $db->prepare("SELECT * FROM cswd_records WHERE
monthname(curdate)='". mysql_real_escape_string($myr) ."'
AND year(curdate)='". mysql_real_escape_string($myr) ."'");
修改
$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]) ."'");
答案 1 :(得分:0)
解决方案:
$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