编辑CSS的PHP网格


editing CSS of PHP grid

我有一个可编辑的网格,我想编辑CSS,使文本区域显示最大宽度,但不知怎么的,我不能增加文本区域的宽度。

我的数据库有三列:

  1. ID
  2. <
  3. 名称/gh>
  4. 八卦

我正在检索一切,并显示它在一个可编辑的网格使用PHP。

<

index . php代码/strong>

<?php
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
    die('Check the database connection again!');
}
$userQuery = 'SELECT Id,Name,Gossip FROM bollywood';
$stmt = $db->query($userQuery);
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="style.css" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                var textBefore = '';
                $('#grid').find('td input').hover(function() {
                    textBefore = $(this).val();
                    $(this).focus();
                }, function() {
                    var $field = $(this),
                        text = $field.val();
                    $(this).blur();
                    // Set back previous value if empty
                    if (text.length <= 0) {
                        $field.html(textBefore);
                    } else if (textBefore !== text) {
                        // Text has been changed make query
                        var value = {
                            'row': parseInt(getRowData($field)),
                            'column': parseInt($field.closest('tr').children().find(':input').index(this)),
                            'text': text
                        };
                        $.post('user.php', value)
                        .error(function() {
                            $('#message')
                                .html('Make sure you inserted correct data')
                                .fadeOut(3000)
                                .html('&nbsp');
                            $field.val(textBefore);
                        })
                        .success(function() {
                            $field.val(text);
                        });
                    } else {
                        $field.val(text);
                    }
                });
                // Get the id number from row
                function getRowData($td) {
                    return $td.closest('tr').prop('class').match(/'d+/)[0];
                }
            });
        </script>
        <title></title>
    </head>
    <body>
    <?php if ($stmt): ?>
    <div id="grid">
    <p id="message">Click on the field to Edit Data</p>
    <table>
        <thead>
            <tr>
                <th>Id</th>
                <th>Name</th>
                <th>Gossip</th>
            </tr>
        </thead>
        <tbody>
        <?php while ($row = $stmt->fetch_assoc()): ?>
            <tr class="<?php echo $row['Id']; ?>">
                <td><input type="text" value="<?php echo $row['Id']; ?>" /> </td>
                <td><input type="text" value="<?php echo $row['Name']; ?>" /></td>
                <td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
            </tr>
        <?php endwhile; ?>
        </tbody>
    </table>
    </div>
    <?php else: ?>
        <p>No actors added yet</p>
    <?php endif; ?>
    </body>
</html>
<

user.php代码/strong>

     <?php
// Detect if there was XHR request
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
    strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
    $fields = array('row', 'column', 'text');
    $sqlFields = array('Id', 'Name', 'Gossip');
    foreach ($fields as $field) {
        if (!isset($_POST[$field]) || strlen($_POST[$field]) <= 0) {
            sendError('No correct data');
            exit();
        }
    }
    $db = new mysqli('localhost', 'root', '', 'bollywood');
    $db->set_charset('utf8');
    if ($db->connect_errno) {
        sendError('Connect error');
        exit();
    }
    $userQuery = sprintf("UPDATE bollywood SET %s='%s' WHERE Id=%d",
            $sqlFields[intval($_POST['column'])],
            $db->real_escape_string($_POST['text']),
            $db->real_escape_string(intval($_POST['row'])));
    $stmt = $db->query($userQuery);
    if (!$stmt) {
        sendError('Update failed');
        exit();
    }
}
header('Location: index.php');
function sendError($message) {
    header($_SERVER['SERVER_PROTOCOL'] .' 320 '. $message);
}
<

style.css代码/strong>

body {
    font: normal 14px Comic Sans, Comic Sans MS, cursive;
}
table {
width: 500px;
}
td, th {
    border: 1px solid #d8d8bf;
}
th {
    padding: 5px;
    font: bold 14px Verdana, Arial, sans-serif;
}
td {
    padding: 10px;
    width: 200px;
}
td input {
    margin: 0;
    padding: 0;
   // width:200px;
    font: normal 14px sans-serif;
    /** Less flicker when :focus adds the underline **/
    border: 1px solid #fff;
}
td input:focus {
    outline: 0;
    border-bottom: 1px dashed #ddd !important;
}
#grid input {
   // width: 200%;
}

你做错了

<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
应:

<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>

textarea是HTML标签名称,而不是输入类型。修改一下

<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>

<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>

还添加了这个css。

<style>
 textarea {
  resize: both;
  width:700px;
 }
</style>

你还确定你可以使用这个获取内容。

<?php echo $row['Gossip']; ?>