我正在使用 Editable Grid http://www.editablegrid.net/en/faq使我的数据库可编辑。我下载了所有内容并进行了设置,只有当我添加多个“日期”列时它才能完美运行日期返回为 000-00-00,这是标准的 mysql 格式,而不是演示列向用户显示的原始日/月(字母)/年格式。我是 PHP 和 jQuery 的最大菜鸟。任何解决此问题的建议或见解将不胜感激。我在脚本末尾添加了一个 not 从我怀疑是问题的行中。
/**
* This script loads data from the database and returns it to the js
*
*/
require_once('config.php');
require_once('EditableGrid.php');
/**
* fetch_pairs is a simple method that transforms a mysqli_result object in an array.
* It will be used to generate possible values for some columns.
*/
function fetch_pairs($mysqli,$query){
if (!($res = $mysqli->query($query)))return FALSE;
$rows = array();
while ($row = $res->fetch_assoc()) {
$first = true;
$key = $value = null;
foreach ($row as $val) {
if ($first) { $key = $val; $first = false; }
else { $value = $val; break; }
}
$rows[$key] = $value;
}
return $rows;
}
// Database connection
$mysqli = mysqli_init();
$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
$mysqli->real_connect($config['db_host'],$config['db_user'],$config['db_password'],$config['db_name']);
// create a new EditableGrid object
$grid = new EditableGrid();
/*
* Add columns. The first argument of addColumn is the name of the field in the databse.
* The second argument is the label that will be displayed in the header
*/
$grid->addColumn('id', 'ID', 'integer', NULL, false);
$grid->addColumn('freelance', 'Complete', 'boolean');
$grid->addColumn('name', 'Name', 'string');
$grid->addColumn('id_continent', 'Assigned To', 'string' , fetch_pairs($mysqli,'SELECT id, name FROM continent'),true);
$grid->addColumn('lastvisit', 'Assigned Date', 'date');
$grid->addColumn('cdate', 'CheckDate', 'date');
$grid->addColumn('ddate', 'DueDate', 'date');
/* The column id_country and id_continent will show a list of all available countries and continents. So, we select all rows from the tables */
//Ramon note that "NULL,false" here means that it cannot be edited so ponte trucha, cabron!!!!
$grid->addColumn('email', 'Email', 'html',NULL,false);
//I suspect it has to do with this line.Question poster comment.
$result = $mysqli->query('SELECT *, date_format(lastvisit, "%d/%m/%Y") as lastvisit FROM demo LIMIT 100');
$mysqli->close();
// send data to the browser
$grid->renderXML($result);