PHP SQL上一个和下一个日期导航

时间:2014-03-07 04:42:39

标签: php mysql sql

我有这个代码,我用来显示当天的比赛

<?php
$today = date('Y-m-d');
$data = mysql_query("SELECT * FROM todaysmatches where matchdate=$today") or die(mysql_error()); 

echo "<h4>$today Matches</h4> </br>";

//table
if(mysql_num_rows($data)==0){
    echo " No Matches";
}else{      
    echo "<table border='1'>
            <tr>
                <th>Match</th>
                <th>Tourmanet</th>
                <th>Date</th>
            </tr>";

    while($info = mysql_fetch_array( $data )){
        echo "<tr>";
        echo "<td>" . $info['curmatch'] . "</td>";
        echo "<td>" . $info['tournamentname'] . "</td>";
        echo "<td>" . $info['matchdate'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
}
?>

我想得到的是前一天和第二天的2个按钮,可以查询并检索该日期的数据,这些按钮可以多次点击而不仅仅是

1 个答案:

答案 0 :(得分:0)

试试这个

<?php
//$today = date('Y-m-d');
 $firstdate = $_POST['firstdate']; // first date which is today
$seconddate = $_POST['seconddate']; //or make this some date you want

//if submit button is pressed do this
if(isset($_POST['submit'])){

$data = mysql_query("SELECT * FROM todaysmatches where matchdate=$today") 
or die(mysql_error()); 

echo "<h4>$today Matches</h4> </br>";

//table
if (empty($data)){
 echo " No Matches";
 }
else{

echo "<table border='1'>
<tr>
<th>Match</th>
<th>Tourmanet</th>
<th>Date</th>
</tr>";

while($info = mysql_fetch_array( $data ))
 {
echo "<tr>";
echo "<td>" . $info['curmatch'] . "</td>";
echo "<td>" . $info['tournamentname'] . "</td>";
 echo "<td>" . $info['matchdate'] . "</td>";
echo "</tr>";
}
echo "</table>";
}

}//end submit button press
?>

<form action="" method="POST">
<input type="hidden" name="firstdate" value="<?php echo date('Y-m-d'); ?>"/>
<input type="submit" name="submit" value="submit" />
</form>

<form action="" method="POST">
<input type="hidden" name="seconddate" value=""/>
<input type="submit" name="submit" value="submit" />

 </form>