将显示/隐藏JQuery脚本协调到PHP中
我目前有一些php脚本,可以输出查询结果。我想在末尾添加两个按钮,它们将显示/隐藏最终元素,但不确定如何执行此操作 以下是我的php脚本:将显示/隐藏JQuery脚本协调到PHP中,php,jquery,html,function,button,Php,Jquery,Html,Function,Button,我目前有一些php脚本,可以输出查询结果。我想在末尾添加两个按钮,它们将显示/隐藏最终元素,但不确定如何执行此操作 以下是我的php脚本: while($result = mysqli_fetch_array($iname)) { echo "<b>Event Name:</b> " .$result['EventName']; echo "<br> "; echo "<b>Location:</b> ".$result['Locati
while($result = mysqli_fetch_array($iname))
{
echo "<b>Event Name:</b> " .$result['EventName'];
echo "<br> ";
echo "<b>Location:</b> ".$result['Location'];
echo "<br>";
//this is where I would like to add my two buttons, that would show the "hidden" content when clicked
while($result=mysqli\u fetch\u数组($iname))
{
echo“事件名称:”.$result['EventName'];
回声“
”;
回声“位置:”.$result['Location'];
回声“
”;
//这是我想要添加我的两个按钮的地方,当点击时,这两个按钮将显示“隐藏”的内容
以下是我在HTML脚本中编写的内容,我希望将其协调到PHP输出中:
<!DOCTYPE html>
<html>
<head>
<scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js></script>
<script>
$(document).ready(function(){
$("#hidden").hide();
$("#hide").click(function(){
$("#hidden").hide(500);
});
$("#show").click(function(){
$("#hidden").show(500);
});
});
</script>
</head>
<body>
<button id="show">Show</button>
<button id="hide">Hide</button>
<p id="hidden">
Some Random Text that will be shown when the buttons are clicked
</p>
</body>
</html>
如果您使用$num\u rows=mysql\u num\u rows($result)获得结果行的数量如何;
然后,在循环中放置一个计数器
$counter=1;
$theClass=“”;
而($result=mysqli\u fetch\u数组($iname))
{
如果($counter==mysql_num_rows($result);){
$theClass=“showHide”;
}
回声“;
echo“事件名称:”.$result['EventName'];
回声“
”;
回声“位置:”.$result['Location'];
回声“
”;
回声“
$counter++;
}