[英]Fade in SQL results with jQuery
I have a php file that I have pulling in SQL elements from my database. 我有一个php文件,已从数据库中提取SQL元素。 My goal is that for each row of data that the div 'moredetails' would fade in on click (one at a time). 我的目标是,对于div“更多细节”在点击时淡入的每一行数据(一次)。 However, the current script I am using only fades in the first result. 但是,我正在使用的当前脚本仅在第一个结果中淡入淡出。 So any row after that does not carry the function. 因此,此后的任何行均不包含该功能。
Here is my code: 这是我的代码:
<?php
session_start();
// If the user is not logged in redirect to the login page...
if (!isset($_SESSION['loggedin'])) {
header('Location: index.html');
exit();
}
$userLoggedIn = $_SESSION['name'];
$con=new mysqli("IPHERE","USERNAMEHERE","PASSWORDHERE","DATABASEHERE");
if($con->connect_error){
echo 'Connection Failed: '.$con->connect_error;
}else{
$sql="select * from mytable WHERE customer LIKE'%$userLoggedIn%'";
$res=$con->query($sql);
while($row=$res->fetch_assoc()){
echo '<table width="50%" class="tabledetails"><tr><td width="20%">Date: </td><td width="20%">Order: </td><td width="20%">Amount: </td>
<tr><td>'.$row["date"], '</td><td>'.$row["num"],'</td><td>'.$row["total"],'</td></tr>
<tr><td><div class="hidden moredetails">'.$row["description"],'</div></td></tr>
</table>'
;
echo "<br><br>";
}
}
?>
<script>
$(document).ready(function(){
$(this).on("click", function(){
$(".tabledetails").click(function(){
$(".moredetails").fadeIn("slow");
});
});
});
</script>
Does anyone know if perhaps I need to rework the jQuery here with some sort of .each
function or have I missed a step in the SQL/php side? 有谁知道我是否需要使用某种.each
函数在这里重新设计jQuery,或者我错过了SQL / php方面的一步?
Note that the class "hidden" is in a css file that says: display:none
请注意,类“ hidden”在一个css文件中,该文件display:none
Like i mentioned in the above comment, use classes: https://jsfiddle.net/wwWaldi/3xy4woq7/54/ 就像我在上面的评论中提到的那样,使用类: https : //jsfiddle.net/wwWaldi/3xy4woq7/54/
$('.tabledetails').on('click', function() {
$(this).find('.moredetails').toggle('slow');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.