无法从数据库中检索数据 [英] can't retrive the data from database

查看:155
本文介绍了无法从数据库中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是脚本如果我选择日期,然后我从数据库获取数据。但如果我选择任何日期,那么我不能从数据库中选择日期从日历的任何数据。可以有人固定吗?

here is script if i select the date then i get the data from database. but if i select any date then i can't get any data from database of selecting date from calender. can some one fixed it ?

<script language="JavaScript" type="text/javascript" src="calendar/calendar.js"></script>
<script src="jquery.js"></script>
<script>
$(document).ready(function()
{
//ajaxTime.php is called every second to get time from server
var refreshId = setInterval(function()
{
 $('#timeval').load('ajaxTime.php?randval='+ Math.random());
}, 1000);

//stop the clock when this button is clicked
$("#stop").click(function()
{
 clearInterval(refreshId);
});
});
</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="d1"> </td>
        </tr>
        <tr  bgcolor="#FF6600">
            <td><font color=#2F4F4F><h2>Draw Time</h2></font></td>
            <td><font color=#2F4F4F><h2>Wining Number</h2></font></td>
          </tr>
        </form>
<tbody>
<?php
include('connect.php');
if (isset($_GET["d1"])) { $d1= $_GET["d1"]; } else { $d1=('YYYY-MM-DD'); }; 
$result = $db->prepare("SELECT * FROM birthday WHERE date = :a");
$result->bindParam(':a', $d1);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<tr class="record">
            <tr  bgcolor="#EEF3E2">
<td><font size=5><font color='#008B00'><?php echo $row['dt']; ?></font></td>
<td><font size=5><font color='#008B00'><?php echo $row['wn']; ?></font></td>
<?php
}
?>
</tbody>
</table>


推荐答案

好,这里有一大块代码,在表单标签。我不知道为什么你继续把隐藏的输入。你不需要它,只要日历输入被称为d1。如果添加具有相同名称的第二个输入,则将消除正确的值,并且您永远不会从日历输入中获取日期。

Ok, here's a big chunk of your code, starting at the form tag. I don't know why you keep putting that hidden input back. You don't need it, provided that the calendar input is called d1. If you add a second input with the same name, you will eliminate the correct value, and you'll never get the date from the calendar input.

    <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"> </td>
    </tr>
    <tr bgcolor="#FF6600">
        <td><font color="#2F4F4F"><h2>Draw Time</h2></font></td>
        <td><font color="#2F4F4F"><h2>Wining Number</h2></font></td>
      </tr>
    </form>
    <tbody>

<?php
include('connect.php');

if (isset($_GET["d1"])) { 
    $d1= $_GET["d1"]; 
} else { 
    $d1=date('YYYY-MM-DD'); 
}

$result = $db->prepare("SELECT * FROM birthday WHERE date = :a");
$result->bindParam(':a', $d1);
$result->execute();

while($row = $result->fetchAll()){
?>

<tr class="record">
    <tr  bgcolor="#EEF3E2">
    <td><font size="5"><font color="#008B00"><?php echo $row['dt']; ?></font></td>
    <td><font size="5"><font color="#008B00"><?php echo $row['wn']; ?></font></td>
    </tr>

<?php  }   ?>

    </tbody>
    </table>

这篇关于无法从数据库中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆