I am currently working on a little project and I only just realised that the way I thought it would work, won't in fact work as JavaScript variables can't be sent to PHP that easily.
I have a Database full of members and each member has an id from 0 to x (lets just say x = 10
) and I wanted to use a JavaScript for loop to iterate through and create everything easily.
Basically, the end product should be the following (except where it says id = 0
it would be different for each entry)
<tr>
<td><?php echo mysql_fetch_assoc(mysql_query("SELECT name FROM squad WHERE id = 0"))['name'] ?></td>
<td><?php switch(mysql_fetch_assoc(mysql_query("SELECT rank FROM squad WHERE id = 0"))['rank']){case 3:echo 'Lieutenant';break;case 2:echo 'Soldier';break;default:echo 'Private';} ?></td>
<td><?php echo number_format(mysql_fetch_assoc(mysql_query("SELECT power FROM squad WHERE id = 0"))['power']); ?></td>
<td><input type="number" name="gained0" value="<?php echo mysql_fetch_assoc(mysql_query("SELECT power FROM squad WHERE id = 0"))['power']; ?>"></td>
<td><input type="number" name="rank0" value="<?php echo mysql_fetch_assoc(mysql_query("SELECT rank FROM squad WHERE id = 0"))['rank'] ?>"></td>
</tr>
Obviously I can't type in a JavaScript variable into PHP so how would I be able to loop through and create the above for all entries?