3

I have a problem how can I use slick grid, it does not have a documentation on how to use it with PHP so I made mine. But I ran into a problem. How would I echo my MySql Query to look like this:

$(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);
}

This is from the slick grid and I need to make my query turn out to be like this. I don't know would I use json_encode or what? I tried the answer in This older Post but I cannot make it run any advice.

By the way here is my table just in case. .

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 ;

my query is just select * from city;

Cœur
  • 37,241
  • 25
  • 195
  • 267
tomexsans
  • 4,454
  • 4
  • 33
  • 49

2 Answers2

3

codeigniter eample you can use it with core 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();
}

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

on view page use,

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

I am using this and its working fine for me

Rob
  • 415,655
  • 72
  • 787
  • 1,044
0

i just needed to echo out, here is my code :

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


}

The answer was taken from THIS POST i just needed to echo it out

Community
  • 1
  • 1
tomexsans
  • 4,454
  • 4
  • 33
  • 49