I have a set of plays that are stored in an array while the user is playing. The user has a board in the screen where I want to print the plays (words) he/she did. I tried passing to an array and then print in the html which didn't work so I asked one of my teacher how I could do it.
He told me to create a function to print the output and the html (I've never done this type of function before) where the array $row
(or any other name) is passed internaly to the function, and then I should call the function inside the loop where the array $row
is passed as a parameter.
I tried to do what he told me, so I did the following:
PHP
$sqlplays="Select word from plays where usertype=2 and idgame=$idgame";
$result=mysqli_query($link, $sqlplays);
for($i=0;$i<10 && ($row=mysqli_fetch_assoc($result)) ;$i++){
print($row);
//rest of the code
}
Java Script
<script>
function print(row){
var aword=[];
aword=jogadas;
for (var i = 1; i <= 10 ;){
$('.word').append(aword[i]).show();
}
}
</script>
HTML
<div id="row" class="esq">
<span class="attempt">1 :</span>
<span class="word"> //Where it should print </span>
</div>
When the user makes the first play the page shows an error saying: "`Error: Call to undefined function print() in (...) "
I don't understand why is this happening, can someone tell me what is the problem? And also, I've never done functions to print html before, if you could tell me if the function is printing correctly I would appreciate.
Thank you in advance.