【问题标题】:Update a whole table with mysqli and php用 mysqli 和 php 更新整个表
【发布时间】:2017-01-13 20:34:32
【问题描述】:

我创建了一个页面来列出所有用户及其在网站上的权限。我使用下面的代码来创建和填充表格,效果很好。

echo '<form method="post" id="detail" class="group" action="includes/setup_change.php?change=rights">';
echo '<div class="group">';
if (!empty($_GET['change'])) {
    if ($_GET['change'] == 'rights') { echo '<span class="message_alert success"><span class="icon success"></span><span class="text">' . _('Your password was successfully changed') . '.</span></span>'; }
}
echo '<h2>' . _('Change') . ' ' . _('rights') . '</h2>';
// select database
    mysqli_select_db( $mysqli, 'db_ccadmin' );
// check connection
if ( $mysqli->connect_errno > 0 ) {
    trigger_error( _('Database connection failed') . ': '  . $mysqli->connect_error, E_USER_ERROR );
}
// sql query
$sql = "SELECT * FROM users";
$res = $mysqli->query( $sql );
if( !$res ) {
    trigger_error( _('Wrong') . ' SQL: [' . $sql . ']. ' . _('Error') . ' : [' . $mysqli->error . ']' );
} else {
    echo '<table id="table_sort_no_search">';
    echo '<thead><tr>
            <th class="username">' . _('Username') . '</th>
            <th class="readonly">' . _('Read-only') . '</th>
            <th class="manage">' . _('Manage') . '</th>
            <th class="admin">' . _('Admin') . '</th>
        </tr></thead>'; 
    echo '<tbody>';
    // output query results
    while($row = $res->fetch_assoc()) {
        echo '<tr>'; 
        echo '<td><input type="text" name="username" value="' . $row['username'] . '" readonly></td>';
        echo '<td><label><input type="radio" class="rights" name="rights_' . $row['username'] . '" value="1" ' . (isset($row['rights']) ? (($row['rights'] == '1') ? 'checked="checked"' : '' ) : '') . '></label></td>';
        echo '<td><label><input type="radio" class="rights" name="rights_' . $row['username'] . '" value="2" ' . (isset($row['rights']) ? (($row['rights'] == '2') ? 'checked="checked"' : '' ) : '') . '></label></td>';
        echo '<td><label><input type="radio" class="rights" name="rights_' . $row['username'] . '" value="3" ' . (isset($row['rights']) ? (($row['rights'] == '3') ? 'checked="checked"' : '' ) : '') . '></label></td>';
        echo '</tr>'; 
    }
    echo '</tbody>';
    echo '</table>';
    // free results to free up some system resources
    $res->free();

问题在于更新数据库中的整个表。我不知道该怎么做。甚至可以一次更新整个表(如生成的)吗?如果是,如何? 我需要在 setup_change.php 中添加什么代码?

如果你能帮助我,那就太好了!

【问题讨论】:

标签: php database mysqli html-table


【解决方案1】:

不清楚您要更新什么,但这是您可以更新的方式(示例):

$mysqli->query("UPDATE birthday SET Manage = null");

当然,这并不能解决您的问题,因为有无数种方法可以更新整个表。你要更新什么表,要设置什么值?

【讨论】:

  • 我使用上面的代码从数据库生成一个表。在表格中,我可以为每个用户设置权限。当点击提交按钮时,我希望整个表中的所有值都在数据库中更新。
猜你喜欢
  • 2016-07-18
  • 1970-01-01
  • 2016-10-12
  • 2015-01-31
  • 1970-01-01
  • 2023-03-15
  • 2019-06-11
  • 2013-03-13
  • 1970-01-01
相关资源
最近更新 更多