如何添加多个“日期”列到可编辑网格,仍然可以正常工作


How to add multiple "date" columns to Editable Grid and still have it work properly?

我使用edititable gridttp://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);

大胆猜测:

$result = $mysqli->query('SELECT *, date_format(lastvisit, "%d/%m/%Y") as lastvisit, date_format(anotherdate, "%d/%m/%Y") as anotherdate FROM demo LIMIT 100');

为每个日期使用date_format(fieldname, formatstring) as name_as_you_want_it_returned