Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

php - can't retrive the data from database

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...