There is a dropdown that shows the user id. When I click on the drop down, displays the user id's of all the members in the database. 1 through however many. It doesn't matter what ID that I choose thoug; it only calls the last user id in the database. When I click the edit button, it shows their information, but always the last users id. So if I have 10 users, and I click to edit number 3, it only goes to user number 10 no matter what. I'm sure it's something to do with my foreach, but haven't figured it out.
Code: Select all
<?php
$result = mysql_query("SELECT * FROM stats");
echo "<table border = '1' id='table2'>
<tr>
<th>ID</th>
<th>Gold</th>
<th>Attack</th>
<th>Defense</th>
<th>Food</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['gold']."</td>";
echo "<td>".$row['attack']."</td>";
echo "<td>".$row['defense']."</td>";
echo "<td>".$row['food']."</td>";
echo "</tr>";
}
echo "</table>";
?>
<form>
<?php
$select = mysql_query("Select id FROM stats");
echo "<SELECT>";
while($result = mysql_fetch_array($select))
{
foreach ($result as $value)
{
echo "<OPTION>";
}
echo $value;
echo "</OPTION>";
}
echo "</SELECT>";
$result = mysql_query("SELECT * FROM stats WHERE id='".$value."'");
$fetch = mysql_fetch_array($result);
?>
<input type="button" id="button1" value="Edit" onClick="return clearTable()">
</div>
<div class="panel2">
<br>Gold <input type = "text" name= "editName" ID= "edit1"
value= "<?php echo $fetch['gold'];?>">
<br>Attack <input type="text" name="editSurname" ID="edit2"
value= "<?php echo $fetch['attack']?>">
<br><input type="button" id="button2" value="Update" onClick="javascript:updateTable();">
</div>
</form>
</body>
</html>