我有一个事务表,其中的条目在按钮单击时在其他数据库表中执行单独的任务。
我需要做的是,在完成每个任务后,相应的行应该变为绿色,而那些未完成的行将逐个变为红色(使用引导程序),而不会刷新页面。
这是我显示的表格代码:
<?php
$sth01 = $dbo->prepare("SELECT * FROM le_planning.transactions");
$sth01->execute();
$result01 = $sth01->fetchAll(PDO::FETCH_ASSOC);
$count01 = $sth01->rowCount();
if ($count01 > 0) {
echo "<div class='container'>
<table class='table table-hover table-bordered table-condensed' id='tab1' name='tab1' style='width:80%' align='center'>
<tr>
<th>Sl. no.</th>
<th>Type</th>
<th>Proposed date</th>
</tr>";
foreach ($result01 as $k) {
if ($k['status'] == 0) {
?>
<tr class="info">
<td><?php echo $k['Transaction_ID']; ?></td>
<td><?php echo $k['Type']; ?></td>
<td><?php echo $k['Datetime']; ?></td>
</tr>
<?php
} else if ($k['status'] == 1) {
?>
<tr class="success">
<td><?php echo $k['Transaction_ID']; ?></td>
<td><?php echo $k['Type']; ?></td>
<td><?php echo $k['Datetime']; ?></td>
</tr>
<?php
} else if ($k['status'] == 2) {
?>
<tr class="danger">
<td><?php echo $k['Transaction_ID']; ?></td>
<td><?php echo $k['Type']; ?></td>
<td><?php echo $k['Datetime']; ?></td>
</tr>
<?php
}
}
echo "</table>
</div>";
} else
echo "";
if (!empty($_POST['validate_sub']))
{
$sth1 = $dbo->prepare("SELECT * FROM le_planning.transactions ORDER BY Datetime ASC");
$sth1->execute();
$result1 = $sth1->fetchAll(PDO::FETCH_ASSOC);
//print_r($result1);
$count1 = $sth1->rowCount();
if($count1 > 0)
{
foreach($result1 as $item)
{
$Trans_ID = $item['Transaction_ID'];
$Type = $item['Type'];
$Type_ID = $item['Type_ID'];
$Datetime = $item['Datetime'];
if($Type=='Production')
{
// some code
}
if($count2==($a+$b))
{ // turn green
$q5 = "UPDATE le_planning.transactions SET status=1 WHERE Transaction_ID=$Trans_ID";
$sth5 = $dbo->prepare($q5);
if($sth5->execute())
echo "";
else
echo "Error!";
}
else
{ // turn red
$q6 = "UPDATE le_planning.transactions SET status=2 WHERE Transaction_ID=$Trans_ID";
$sth6 = $dbo->prepare($q6);
if($sth6->execute())
echo "";
else
echo "Error!";
}
}
}
}
}
}
?>
<form role="form" method="post" name="f1" id="f1" action="<?php echo $SERVER[PHP_SELF]; ?>">
<center><input type="submit" value="Validate" class="btn btn-success" id="validate_sub" name="validate_sub"></center>
</form>
到目前为止,我已经明白为了使每个事务立即改变颜色,或者可以说实时更新,而所有事务都花时间执行而不刷新页面,我必须使用jquery和ajax但我无法编写逻辑这个。
PS - 我是jQuery&amp;的新手AJAX。
真的很感激任何帮助。谢谢!
答案 0 :(得分:0)
检查此链接。您从这里找到的相关问题解决方案。
http://www.9lessons.info/2011/03/live-table-edit-with-jquery-and-ajax.html
{{3}}