2013-05-03 18 views
-3

我正在使用可編輯網格http://www.editablegrid.net/en/faq使我的數據庫editable.I下載一切,並設置它,它的工作原理只有當我添加多個「日期」列日期的格式回來爲000-00-00其中是標準的mysql格式,而不是演示列向用戶顯示的原始日/月(字母)/年格式。我是PHP和jQuery中最大的總noob。任何建議或洞察力來解決這個問題將不勝感激。我添加了一個不是從我懷疑是問題的行腳本的末尾。如何將多個「日期」列添加到可編輯網格並仍然正常工作?

/** 
* 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); 
+0

請與評論的人? – NewHistoricForm 2013-05-03 23:47:29

+0

請理解,我們無法在此提供對第三方腳本的支持。請聯繫您在此處使用的軟件的供應商以獲取支持選項。或者把問題歸結爲一個具體的編程問題,然後詢問它。 – hakre 2013-05-04 04:35:24

+0

你可能會喜歡這個:http://www.codecademy.com/tracks/php - 讓我知道它是否對你有幫助。 – hakre 2013-05-04 06:10:34

回答

0

大膽猜測:

$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每一個日期

+0

哈哈哈哈哈。老兄,這是如此簡單,但老兄,它的工作!我真的需要把我的PHP!我愛PHP btw!你的搖滾樂!謝謝,親愛的。我找到了你的回憶。也謝謝你stackoverflow!我喜歡這個編程大師和極客的社區。你所有的酒都沒事!感謝一堆。只是讓我想更多地瞭解有關php和所有其他服務器端語言的所有內容。是啊! – NewHistoricForm 2013-05-04 05:43:52

+0

你能解釋一下嗎? – NewHistoricForm 2013-05-04 05:55:13

相關問題