dourui9570 2015-06-05 16:08
浏览 70

在PHP中循环脚本

Well im having this problem and cant resolved it would like to have some help from you guys, so here it is:

I have this code:

<?php if (mysql_num_rows($tournaments) !=0){
do { ?>
<div id="mainContainer">
    <div id="leftContainer">
        <img src="images/tournaments/<?php echo $row_tournaments['logo']; ?>.png">
    </div>
    <div id="rightContainer">
        <div id="rightContent">
            <p><?php echo $row_tournaments['description']; ?></p>
            <a href="tournaments.php?id_tournament=<?php echo $row_tournaments['id_tournament']; ?>">
                <div id="galleryButton">
                    <p>Entrar no torneio</p>
                </div>
            </a>
        </div>
        <div id="rightDetails">
            <i class="fa fa-gamepad"></i>
            <a href="games.php?id_game=<?php echo $row_tournaments['id_game']; ?>">
                <?php echo $row_tournaments['game']; ?>
            </a>
            <br>
            <i class="fa fa-calendar-o"></i>
            <a href="#">
                <?php echo $row_tournaments['date']; ?>
            </a>
            <br>
            <i class="fa fa-pencil-square-o"></i>
            <a href="tournaments.php?id_tournament=<?php echo $row_tournaments['id_tournament']; ?>#disqus_thread">
                Sem comentários
            </a>
            <br>

            <script type="text/javascript">
            function giveThatInputAValue(){
                var elem = document.getElementById("search");
                elem.value = "<?php echo $row_tournaments['city']; ?>";
                /*document.forms["form"].submit();
            */}
           </script>
           <i class="fa fa-map-marker"></i>
           <a onClick="giveThatInputAValue()">
               <?php echo $row_tournaments['city']; ?>
           </a>
           <br>

           <img src="images/<?php echo $row_tournaments['online']; ?>.png">
           <a href="#">
               <?php echo $row_tournaments['online']; ?>
           </a>
       </div>
   </div>
</div>
<?php } while ($row_tournaments = mysql_fetch_assoc($tournaments));
} else {
?>
<div id="noresults">
    <p>Sem torneios</p>
</div>
<?php } ?>

Everything loop fine but this part is not looping at all:

<script type="text/javascript">
function giveThatInputAValue(){
    var elem = document.getElementById("search");
    elem.value = "<?php echo $row_tournaments['city']; ?>";
    /*document.forms["form"].submit();*/
}
</script>

And dont know why is it, someone please help. Cumps.

  • 写回答

2条回答 默认 最新

  • dongyi2993 2015-06-05 16:14
    关注

    You are defining your function in a loop. Over and over again. So when you call your function, which one should it call? Probably all previous ones have been overwritten by the last version.

    You should define your function outside of any loop and then call it with the parameters that you have available in the loop.

    Apart from that you are also adding elements with ID's in your loop. ID's need to be unique as well so you should use classes or give them a unique ID.

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题