0

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.

3
  • 1
    assuming the other stuff, are your going to create a do loop so high up that it morphes into a page with a jillion high level containers and scripts? Commented Jun 5, 2015 at 16:18
  • what i do there is i press the button it will change the value of input and submit the form automatically in search page where the code is already done, the only problem is get the proper value from database to change in input and submit the form Commented Jun 5, 2015 at 16:24
  • ok give me a second. i will put an answer together that is likely to be questionable Commented Jun 5, 2015 at 16:34

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your info but i kinda dont know how to do that :S could you rewrite my code with the fix so i can learn and do it in the future, thanks.
1

a real php programmer knows this (meaning i am not one). been a while away from php.

ok first as i see it you never get your first row from result set (someone advise here). you are checking to see if you have rowcount then plod about. i reserve the right to be very wrong.

try something like

if ($result) {
  while($row = mysql_fetch_array($result)) {
    // output $row info
  }

}
else {
  echo "nada";
}
  1. put your script for the function at the top
  2. don't surround the main div section creations like you are with a loop

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.