您好我是php和mysql的新手。想了解更多..
我正面临一个问题..我的while循环显示所有行但当我尝试更新第二行时它总是更改第一行的特定列。并给我警告消息警告:mysql_fetch_assoc()期望参数1是资源,第217行的C:\ xampp \ htdocs \ flowtask \ users.php中给出的布尔值[whille loop start的开头]这是我的代码 -
假期管理
<tr>
<th>User Name</th>
<th>Starts</th>
<th>Length</th>
<th>Status</th>
<th>Update</th>
</tr>
</thead>
<?php
include 'sql.php';
$SQL = "SELECT vacation.start_date, userinfo.*, vacation.length, vacation.status FROM vacation INNER JOIN userinfo ON vacation.user_id = userinfo.user_id ";
$result = mysql_query($SQL);
while($db_field = mysql_fetch_assoc ($result)) {
$uname = $db_field['username'];
$uid = $db_field['user_id'];
$sdate = $db_field['start_date'];
$len = $db_field['length'];
$stat = $db_field['status'];
?>
<tbody>
<tr>
<td><?php echo $uname;?></td>
<td><?php echo $sdate;?></td>
<td><?php echo $len;?></td>
<td><?php echo $stat;?></td>
<td>
<?php
if(isset($_POST['btn-accept']))
{
$SQL = "UPDATE vacation SET status = '1' WHERE user_id = '$uid' ";
$result = mysql_query($SQL);
}
if(isset($_POST['btn-deny']))
{
$SQL = "UPDATE vacation SET status = '0' WHERE user_id = '$uid' ";
$result = mysql_query($SQL);
}
?>
<form method="post" action = "<?php $_PHP_SELF ?>">
<input type='hidden' value="<?php echo $uid; ?>" >
<button type='submit' class="btn btn-success btn-mini" name="btn-accept" >Accept</button>
<button type='submit' class="btn btn-danger btn-mini" name="btn-deny" >Deny</button>
</form>
</td>
</tr>
<?php } ?><!--while loop end>-->
</tbody>
</table>
</div>`
If I click the 2nd row 'btn-accept' its change the 1st row and show this warning