weixin_33727510 2020-04-03 06:17 采纳率: 0%
浏览 41

更改行颜色sql / php

echo "<tbody";
echo "<tr>";
echo "<td>{$id}</td>";// display customer Id
echo "<td> {$firstname} {$lastname}</td>"; //display customer title,firstname,lastname
echo "<td>{$date->format('h:i A')}</td>";//display the time customer joined the queue
echo "<td><a href='#' onclick='delete_user({$id});'  
class='btn btn-danger'>btn</a> ";// Delete Record Link
  echo "<td><a href='#' onclick='delete_user2({$id});'  
class='btn btn-danger'>btn</a> ";// Delete Record Link
echo "<td align='center'>" . '<input type="button" value="Accept" name="txtaccept" onclick="Accept(this)">&nbsp;&nbsp;&nbsp;<input type="button" value="Reject" name="txtreject" onclick="Reject(this)">' . "</td>";

echo "</tr>";
echo "</tbody";
} // End while()

echo "</table>";


    <style type="text/css">
table { border-collapse: collapse; } //to remove cell spacings
table td { padding: 2px; }
tr.accepted, tr.accepted td { background-color: green; }
tr.rejected, tr.rejected td { background-color: red; }
</style>

    <script type="text/javascript">
function Accept(el)
{
   var tr = el.parentNode.parentNode; //tr
   tr.className = "accepted";
}
function Reject(el)
{
   var tr = el.parentNode.parentNode; //tr
   tr.className = "rejected";
}
</script>

Hello there is my code that works fine,to explain,when I click button accept it changes color to table row in green and clicking reject changes color to red,my problem is that when I refresh page results are refreshing too,How can I save this result I get by clicking these buttons? I am really new,Its silly question may be but you can save my day.

  • 写回答

1条回答 默认 最新

  • weixin_33730836 2020-04-03 06:27
    关注

    Put you logic when you printing row. For example:

    Change

    echo "<tr>";
    

    To

    echo "<tr ".($value ? ($value == 'accepted' ? "class='accepted'" : "class='rejected'") : "").">";
    

    $value -> your column in database where you save if it is accepted or rejected.

    评论

报告相同问题?