单击时显示数据库中的特定数据

时间:2013-10-11 18:36:22

标签: php jquery html mysql

我有一个代码,其中div根据数据库中的id数量而来,点击它们应该来自它们的相关数据(这里,状态)但它不会这样,当我点击它们所有数据来时在一个div而不是多个。 代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>New Twitter Design - 9lessons</title> 
<meta content='New twitter design tutorial with jquery and ajax' name='description'/> 
<meta content='New, twitter, design, API, Instant' name='keywords'/> 
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script> 

<script> 
$(document).ready(function() {


   $('.block').click(function()
   {
   var id= $(this).attr('title');
   var data_id= $(".data").html();

    var panel= $('.panel');
    var panel_width=$('.panel').css('left');


    // if(data_id==id)
    // {
    panel.animate({left: parseInt(panel.css('left'),0) == 0 ? +panel.outerWidth() : 0});
    // }
    // else
    // {


    // if(panel_width=='341px')
    // {

    // }
    // else
    // {

    // panel.animate({left: parseInt(panel.css('left'),0) == 0 ? +panel.outerWidth() : 0});

    // }

    // }
    // $('.data').html(title);
    // return false;

  });



  $('.close').click(function() 
   {

    var panel= $('.panel');
    panel.animate({left: parseInt(panel.css('left'),0) == 0 ? +panel.outerWidth() : 0});
    return false;

  });



});

</script> 
<style> 

body
{
font-family:'Georgia',Times New Roman, Times, serif;
background:#f2f2f2;
}
h4
{
padding:5px;
}
a{ color:#333 }
a:hover {color:#cc0000}

#container
{
//this is the div which comes after click?
width:700px;margin:0 auto; background-color:#fff; min-height:500px; overflow:auto;

-moz-border-radius:5px;-webkit-border-radius:6px;
border:solid 1px #999999;

}

.right
{
float:right; width:320px;
}
.left
{
float:left; background-color:#fff; width:510px; min-height:300px;
 position:relative;
}
.block
{
border-bottom: dashed 1px #999999;
padding:15px;
border-right:solid 1px #999999;
 }
 .block:hover
 {
 background-color:#ffc72e;
cursor:pointer;


 }

#panel-frame
{
position:relative; max-width:700px; position:fixed;
}
.panel
{

background-color:#f2f2f2; width:500px; height:600px;
margin-top:20px;
position:relative;
position:absolute;
border:solid 1px #999999;
border-left:0px;
left:0;



}
.data
{
font-size:25px

}
.head
{
background-color:#ffc72e;
padding:10px;
text-align:right;
}
#logo
{
width:700px;margin:0 auto;
text-align:left;
}
</style> 
</head> 

<body> 


 <?php $connect = mysql_connect("localhost","root","taaran"); 
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'taaran';

if (!$connect) { die('Could not connect: ' . mysql_error()); }
$sql = 'SELECT * FROM story ORDER BY id DESC';
 mysql_select_db('supscribe'); 
 $retval = mysql_query ( $sql, $connect );
 if(! $retval)
 {
 die('Could not get daya: ' . mysql_error());
 }
// $select = mysql_query("SELECT * FROM story"); 
 //$result = mysql_query($select);


 while($row = mysql_fetch_array($retval, MYSQL_ASSOC)){ 
 //$result = $row['story'];
  $anon = $row['anon'];
 if($anon==1) {
 ?>

<div id='container'> 

<div class='right'> 
<h1>adds :</h1>

</div> 
<div id="panel-frame"> 
<div class="panel"> 
<div class="head"> 
<a href="#" class="close">Close</a> 
</div> 

<div class="data" style="padding:20px" >
<?php

$message_query = mysql_query("SELECT * from story ORDER by id desc");

while($data = mysql_fetch_row($message_query)){
echo $data[2] ;
?>

 <?php }
?>

</div> 

</div> 

</div> 

<div class="left">
<ul> <li> <?php while($row = mysql_fetch_array($retval, MYSQL_ASSOC)){     
$id1 = $row['story_type'];
 ?>
<div class="block" id="">
<form id="someForm" method="post">
        <input type="hidden" name="divData" id="useDataField" value="<?php echo $id; ?>"  />
<h3><font  color = "<?php echo $color; ?>" >Title: </font></h3><mark> <?php echo $row['story_title']; ?></mark> <hr><br>
  <h3><font color = "<?php echo $color; ?>" > Genre: </font> </h3><mark> <?php echo $row['story_type']; ?></mark> <hr><br>
  <h3><font color = "<?php echo $color; ?>" >  Story : </font> </h3><mark> <?php echo $row['story']; ?></mark><hr><br> 
  <h3><font color = "<?php echo $color; ?>" >  Id : </font> </h3><mark> <?php echo $row['id']; ?></mark><hr><br>
  </div>
  <?php  }
?> 

</li></ul>


</div> 

</div>
 <?php }
} ?>
</body> 
</html> 

0 个答案:

没有答案