-
1 Nov 2011 10:58 AM #1
Extjs 4 + PHP + MYSQL
Extjs 4 + PHP + MYSQL
Hello everbody,
i like extjs but i have so many problems.
i need mysql and extjs charts and mysql scripts please somebody help me i need mysql charts with extjs
who help me ?
i cant find this style script !!!
-
15 Nov 2011 11:08 AM #2
Hello mahmutdur,
I'll be glad to help you.
What kind of problems are you encountering? You can contact me by email if you like.
Cheers
-
29 Nov 2011 11:33 PM #3
extjs+php+mysql
extjs+php+mysql
Hello ErnestoR
I am looking for a similar help.This is my php file.
I want to display the fetched results in a grid.What would be resultant grid.js to display the records fetched using the json_encode function.
PHP file:
<?php
$sql2="select * from register";
$result2=mysql_query($sql2);
//$output=mysql_fetch_assoc($result2);
//$output=FetchAll($result2);
/*echo "<pre>";
print_r($output);
exit;*/
for ($i=0; $row = mysql_fetch_array($result2); $i++)
{
$return[$i]['username'] = $row['username'];
$return[$i]['firstname'] = $row['firstname'];
$return[$i]['lastname'] = $row['lastname'];
$return[$i]['email'] = $row['email'];
$return[$i]['state'] = $row['state'];
$return[$i]['city'] = $row['city'];
$return[$i]['country'] = $row['country'];
}
echo json_encode($return);
?>
I have tried this,but does not work
<script type="text/javascript">
Ext.onReady(function() {
Ext.define('Company', {
extend: 'Ext.data.Model',
fields: ['username', 'firstname', 'lastname', 'email']
});
var store_company = new Ext.data.Store({
model: 'Company',
proxy: {
type: 'ajax',
url: 'connection.php',
reader: {
type: 'json',
//root: 'companies'
}
}
});
var grid_company = Ext.create('Ext.grid.Panel', {
store: store_company,
columns:[
{
text : 'User Name',
width : 200,
dataIndex: 'username'
},
{
text : 'Firstname',
width : 200,
dataIndex: 'firstname'
},
{
text : 'Lastname',
width : 200,
dataIndex: 'lastname'
},
{
text : 'Email',
width : 250,
dataIndex: 'email'
}
],
height: 200,
width: 850,
title: 'Company List',
renderTo: 'grid-company',
});
store_company.load();
});
</script>
Any help would be appreciated.
Regards
Sachin
-
30 Nov 2011 12:07 AM #4
@Ernesto
Hello
Just to add to the above post.I am getting my values in the JSON format from the php file.
The output is this
[{"username":"Sachin","firstname":"Sachin","lastname":"Taware","email":"sachi@gmail.com","state":"MH","city":"Pune","country":"India"},{"username":"Rahul","firstname":"Rahul","lastname":"Dravid","email":"rdravid@gmail.com","state":"KA","city":"Bangalore","country":"India"},{"username":"MS","firstname":"MS","lastname":"Dhoni","email":"ms@gmail.com","state":"JH","city":"Ranchi","country":"India"},{"username":"viru","firstname":"Virender","lastname":"Sehwag","email":"viru123@gmail.com","state":"DL","city":"Delhi","country":"India"},{"username":"Gauti","firstname":"Gautam","lastname":"Gambhir","email":"gauti@gmail.com","state":"DL","city":"Delhi","country":"India"},{"username":"jumbo","firstname":"Anil","lastname":"kumble","email":"anil@gmail.com","state":"KA","city":"Bangalore","country":"India"}]
But I am not able to display them in the grid.
Regards
Sachin
-
30 Nov 2011 9:32 AM #5
@sachintaware
As a hint please use CODE tags so we can view your code better.
The problem is in your store configuration and your php output.
Your Store should be configured as
And in your php code it has to return something like thisCode:var store_company = new Ext.data.Store({ model: 'Company', proxy: { type: 'ajax', url: 'connection.php', reader: { type: 'json', root: 'companies'// The READER should have a root } } });
Where companies is the ROOT of your data. By default the successProperty of the store is "success".Code:{ "success": true, "companies": [ {"username":"Sachin","firstname":"Sachin","lastname":"Taware","email":"sachi@gmail.com","state":"MH","city":"Pune","country":"India"}, {"username":"Rahul","firstname":"Rahul","lastname":"Dravid","email":"rdravid@gmail.com","state":"KA","city":"Bangalore","country":"India"},{"username":"MS","firstname":"MS","lastname":"Dhoni","email":"ms@gmail.com","state":"JH","city":"Ranchi","country":"India"}, {"username":"viru","firstname":"Virender","lastname":"Sehwag","email":"viru123@gmail.com","state":"DL","city":"Delhi","country":"India"}, {"username":"Gauti","firstname":"Gautam","lastname":"Gambhir","email":"gauti@gmail.com","state":"DL","city":"Delhi","country":"India"}, {"username":"jumbo","firstname":"Anil","lastname":"kumble","email":"anil@gmail.com","state":"KA","city":"Bangalore","country":"India"}] }
Hope this helps.
-
30 Nov 2011 10:10 PM #6
Extjs 4 + JAVA+ MYSQL
Extjs 4 + JAVA+ MYSQL
@Ernesto
Thank you for the prompt reply and sorry for the inconvenience as it was my first post.
I got it working without the root attribute.But I would like you to throw some light on it.
How can the json_encode function return values with the root name attached to it?
Also,I want to perform the similar operation using JAVA as the backend.I have written a connection class which works fine.But,i am not sure if there is any similar function like json_encode() in java as in PHP.
So,if you can add a code snippet of how I can use servlet to submit the request to json and display in a grid,it will be very helpful.
Regards
Sachin
-
1 Dec 2011 8:37 AM #7
I use something like this for the response:
Response Class
And the implementationPHP Code:<?php
/**
* @class Response
* A simple JSON Response class.
*/
class Response {
public $success, $data, $message, $errors, $tid, $trace;
public function __construct($params = array()) {
$this->success = isset($params["success"]) ? $params["success"] : false;
$this->message = isset($params["message"]) ? $params["message"] : '';
$this->data = isset($params["data"]) ? $params["data"] : array();
}
public function to_json() {
return json_encode(array(
//here is where we create extra values in json
'success' => $this->success,
// 'totalRecords'=>$this->totalRecords, //in Order to use totalRecords we have to declare it for the class
'message' => $this->message,
'data' => $this->data
));
}
}
If you like i can send you a basic example of a CRUD using Extjs4 + PHP +MySQL. Just send me your email in a private message.PHP Code:<?php
//Import Response Class
require_once 'lib/response.php';
//Creating User Class
class User
{
var $userID;
var $name;
var $lastname;
var $age;
}
//Make DB connection
require_once('database_connection.php');
//Query BD
$result = mysql_query("SELECT * FROM Users");
$query_array=array();
$i=0;
//Iterate all Select
while($row = mysql_fetch_array($result))
{
//Create New User instance
$user = new User();
//Fetch User Info
$user->userID=$row['userID'];
$user->name=$row['name'];
$user->lastname=$row['lastname'];
$user->age=$row['age'];
//Add User to ARRAY
$query_array[$i]=$user;
$i++;
}
mysql_close($con);
//Creating Json Array needed for Extjs Proxy
$res = new Response();
$res->success = true;
$res->message = "Loaded data";
$res->data = $query_array;
//Printing json ARRAY
print_r($res->to_json());
?>
And about Java haven't really tried to integrating it with it right now I'm trying to integrate it with Groovy/Grails.
-
13 Mar 2012 8:37 PM #8
Extjs 4 MVC, PHP and MySQL
Due to constant private messages for an example of Extjs4 Php and Mysql I've started a Github account you can download the source code here
https://github.com/ErnestoR/Extjs4_PHP_MySQL
-
13 Mar 2012 8:45 PM #9
Thats really cool!!good job Ernesto.That would surely help many.
Cheers!
Sachin
www.optionsconsultancy.com
-
9 Apr 2012 7:06 AM #10
Awesome job. I am moving over from extjs 3 and this simple example using the proper architecture helped tons.


Reply With Quote