通过选择日期显示mysql数据库值

时间:2014-03-12 21:27:15

标签: php mysql sql

如果你在这里http://www.joomusic.info/joosilver.php,你可以理解我的概念。我已经设置了所有脚本和日历,我在mysql数据库表中创建表名是Firstname,这个表中有2列1,Drawtime和2,winsnumbers。我已经为连接数据库

创建了connect.php文件

这是一半脚本,因为我不知道如何让它充实

<script language="JavaScript" type="text/javascript" src="calendar/calendar.js"></script>
<!--<strong><div align="right" id="timeval" style="color:#FF6600; font-family:Arial, Helvetica, sans-serif">--:--:--</div></strong>--> 
    <table width="420" border="1" >
    <form name="showdraw" action="ooo.php" method="post">
    <tr  bgcolor="#FF6600">
            <td><script> DateInput('cdate', true, 'YYYY-MM-DD'); </script></td>
            <td> <input type="submit" value ="Show"> <input type="hidden" value="Show" name="action"> </td>
    </tr>
    <tr  bgcolor="#FF6600">
        <td><h2>Draw Time</h2></td>
        <td><h2>Wining Number</h2></td>
      </tr>
    </form>
<?php
include('connect.php');

此后包括('connect.php);我在这个页面中添加了哪个php脚本,然后我的脚本像http://joomusic.info/joosilver.php

一样工作

1 个答案:

答案 0 :(得分:0)

好吧,实际上还有很多工作要做,但是我将专注于从数据库中获取结果。基本上,只需从post字符串中提取日期值(我不知道你将它命名为什么,所以我称之为date)。然后,将其传递给您的数据库并循环遍历结果。最后将日期格式化为仅显示小时和分钟,然后将其粘贴到表格中。

// GET THE DATE FROM THE FORM
// I DON'T KNOW WHAT THE NAME OF YOUR DATE FIELD IS, BUT CHANGE IT IN $_POST['FIELD NAME']
$draw_date = date("Y-m-d", strtotime($_POST['date']));


// CONNECT TO THE DATABASE - THIS SHOULD BE SET ALREADY IN YOUR connect.php
$link = mysqli_connect('DATABASE HOST', 'USERNAME', 'PASSWORD', 'DATABASE');


// BUILD OUT THE QUERY TO GET ALL RECORDS WITH THE SAME DRAW DATE AND ORDER THEM BY TIME
$query = "SELECT Drawtime, winningnumbers FROM Firstname WHERE Drawtime = '".$draw_date."' ORDER BY Drawtime";


// EXECUTE THE QUERY
$result = mysqli_query($link, $query) or die("Cannot Get Winning Numbers");


// START PRINTING OUT THE TABLE
print "
        <table>";


// LOOP THROUGH EACH OF THE RESULTS FROM THE DATABASE AND PRINT THEM OUT
while ($row = mysqli_fetch_array($result)) {

    // FORMAT THE DATE SO IT IS ONLY SHOWING THE TIME
    print "
        <tr>
          <td>".date("H:i", strtotime($row['Drawtime']))."</td>
          <td>".$row['winningnumbers']."</td>
        </tr>";

}

// CLOSE UP YOUR TABLE
print "
        </table>";