2013-04-10 2 views
-1

У меня есть редактируемая сетка, где я хочу отредактировать CSS, чтобы текстовая область отображала максимальную ширину, но почему-то я не могу увеличить ширину области текста.редактирование CSS сетки PHP

Моя база данных имеет три колонки:

  1. ID
  2. Имя
  3. Сплетни

Я все извлечения и отображения его в редактируемый сетке с помощью PHP.

код index.php

<?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 код

 <?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 код

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%; 
} 

ответ

-1

Вы делаете это неправильно

<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> 
+0

На этом, как вы сказали, колонка сплетен не заполняется. –

-1

это текстовое поле 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']; ?> 
+0

Я уже пробовал сделать это change.but, но он не заполняет control.and все равно размер не увеличивается. –

+0

@PalakSanghani я меняю ответ. посмотрите пожалуйста. –

+0

Спасибо :) Мне удалось –

Смежные вопросы