Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过ajax切换php循环中的div_Php_Ajax - Fatal编程技术网

通过ajax切换php循环中的div

通过ajax切换php循环中的div,php,ajax,Php,Ajax,大家好,我想要一个在php的while循环中的div在点击按钮时被切换。单击特定按钮时,应切换特定div。 到目前为止,我已经尝试过了,而且效果很好,但只适用于循环的第一个div。只有第一个div被切换,请帮助 “显示注释”是要单击的按钮: <td colspan=2 style="background-color:#FFFBE6;opacity:.89;height:25px;max-height:27px;"> <div style=

大家好,我想要一个在php的while循环中的div在点击按钮时被切换。单击特定按钮时,应切换特定div。 到目前为止,我已经尝试过了,而且效果很好,但只适用于循环的第一个div。只有第一个div被切换,请帮助

“显示注释”是要单击的按钮:

<td colspan=2 style="background-color:#FFFBE6;opacity:.89;height:25px;max-height:27px;">
                    <div style="float:left;margin-left:80px;" id="ratinginadiv">
                    <b class="ratings" id="showcomm" onclick="showcomments(this);"><?=$no_ofcomments?> comments |</b>   <b class="ratings"><?=$no_offollowers?> Following </b> | 
                    <b onclick="displaystars();" class="ratings">Star</b>|</div></td>


div id="commentdiv">
            <table style="background-color:#DDFFFF; border:1px solid #C9D291;width:100%;margin-bottom:0px;border-top:0px;margin-top:0px;" align="center" cellspacing=0>
                    <?php
                    $onid=$postainarray['id'];
                    $selectcomments=mysql_query("select comments,time,onemail,emailid ,hidden from waf where onid_comment='$onid' and comments!='' ");
                    while($commentsinaray=mysql_fetch_array($selectcomments)){
                    $commemail=$commentsinaray['emailid'];
                    $dataofcommenter=mysql_query("select name,pic,email,dob,gender from fk_mem where email='$commemail'");
                    $datainarray=mysql_fetch_array($dataofcommenter);
                    if($commentsinaray['hidden'] == 'hide'){
                    $nameintitle='hidden';
                    $emailintitle='hidden';
                    $picofcomm="blur.jpg";
                    }

                    else{
                    $nameintitle=$datainarray['name'];
                    $emailintitle=$datainarray['email'];
                    $picofcomm=$datainarray['pic'];
                    }
                    ?>
            <tr>
                <td align="center" style="width:55px;background-color:white;opacity:1;border-bottom:2px solid white;">
                    <a title="<?=$nameintitle?>,<?=$datainarray['gender']?>,[<?=$datainarray['dob']?>],<?=$emailintitle?>" href="profile_page_name.php?friendemail=<?=$emailintitle?>"><img src="uploads/<?=$picofcomm?>" style="width:40px;max-height:55px; border:1px solid green;padding:1px;" /></a>
                </td>
                <td align="left" style="background-color:#F3FCFF;opacity:1;border-bottom:2px solid white;">
                    <a href="profile_page_name.php?friendemail=<?=$emailintitle?>" title="Go to <?=$nameintitle?>'s Profile.." style="text-decoration:none;color:#718E99;font-weight:normal;margin-left:5px;margin-bottom:0px;">
                    <?=$nameintitle?></a><br>
                    <p style="margin-left:5px;margin-top:0px;"><?=$commentsinaray['comments']?></p>
                </td>
                <td align="left" style="width:65px;vertical-align:top;border-left:2px solid white;border-bottom:2px solid white;">
                    <small style="color:red;font-size:14px;"><?=$commentsinaray['time']?></small>
                </td>
            </tr>
            <?php } ?>
            <tr>
            </table>
            </div>


function showcomments(obj){
    var currentdiv = $("#commentdiv");
        currentdiv.slideToggle();
    }

评论|如下|
明星|
div id=“commentdiv”>

老兄,老兄…畸形桌子里的div,里面有畸形桌子

toogle的代码无处不在,我想你唯一的问题是没有为每个div分配唯一的id。在循环中添加一个计数器,然后将其添加到div id“commentDiv”

在添加功能之前,请先确定页面的结构