2012-02-21 79 views
3

我有一个问题我如何使用光滑的网格,它没有关于如何使用PHP的文档,所以我做了我的。但是我遇到了一个问题。如何将我赞同我的MySQL查询看起来像这样:slickgrid使用PHP和Mysql填充数据

$(function() { 
for (var i = 0; i < 500; i++) { 
    var d = (data[i] = {}); 

    d["title"] = "Task " + i; 
    d["description"] = "This is a sample task description.\n It can be multiline"; 
    d["duration"] = "5 days"; 
    d["percentComplete"] = Math.round(Math.random() * 100); 
    d["start"] = "01/01/2009"; 
    d["finish"] = "01/05/2009"; 
    d["effortDriven"] = (i % 5 == 0); 
} 

这是华而不实的网格,我需要让我的查询变成这样。我不知道我会用json_encode还是什么?我在This older Post试过了答案,但是我不能让它运行任何建议。感谢前方。 。 。

顺便说一句,这里是我的表,以防万一。 。

CREATE TABLE IF NOT EXISTS `city` (
`ID` int(11) NOT NULL AUTO_INCREMENT, 
`Name` char(35) NOT NULL DEFAULT '', 
`CountryCode` char(3) NOT NULL DEFAULT '', 
`District` char(20) NOT NULL DEFAULT '', 
`Population` int(11) NOT NULL DEFAULT '0', 
PRIMARY KEY (`ID`), 
KEY `CountryCode` (`CountryCode`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4083 ; 

我的查询仅仅是select * from city;

编辑2:解决解决解决解决解决

我只是需要呼应了,这里是我的代码:

$(function() { 
for (var i = 0; i < 500; i++) { 
    var data=[]; 
    <?php echo $data ?> 


} 

答案是取自This post here我只是需要将它回显出来

回答

0

我只是需要呼应了做工精细,这里是我的代码:

$(function() { 
for (var i = 0; i < 500; i++) { 
    var data=[]; 
    <?php echo $data ?> 


} 

答案取自THIS POST我只需要将其回显出来

2

笨eample你可以用PHP核心

/////////////////////////////in Controller page///////////// 

function get_companybyid() 
{ 
    $data=$this->company->get_companybyid(); 

    echo json_encode($data); 
} 

///////////////////////////////////////////////////////////////////////////////////////// 

//////////////////////////////in Model/////////////////////////////////////////////////// 

function get_companybyid() 

{ 
    $CompanyID=$_GET['CompanyID']; 
    $sql = "SELECT 
       CompanyName, 
      FROM 
       Company 
      WHERE CompanyID=". $CompanyID; 

    $query = $this->db->query($sql); 

    return $company_result = $query->result_array(); 
} 

///////////////////////////////////////////////////////////////// 

上查看页面使用方式,因此,

// i am working with codeigniter below i am calling a controlller and method with jquery getjson method passign a company id and retrive th data intoa json variable 

$.getJSON(APP_PATH + "company/get_companybyid", { CompanyID: "1"}, function(json) 
{ 
    for (var i = 0; i < json.length; i++) 
    { 
     var d = (data[i] = {}); 
     d["id"] = "id_" + i; 
     d["num"] = i; 
     d["CompanyName"] = json[i].CompanyName; 
    } 
} 

我使用这个和它的对我来说