473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to load data in extjs using php

Hi, I'm trying to load data to my grid panel which resides in php using JsonStore object. But the problem is JsonStore is not getting data from php only. Can anyone tell me where i've gone wrong. Is my php file is proper or not? I'm very new to both php and extjs. please help me out.
i'm uploading the both .js and .php files. please help me out.

test.js file:
Expand|Select|Wrap|Line Numbers
  1. Ext.onReady(function(){
  2.   alert("inside onReady");
  3.  
  4.   Ext.QuickTips.init();
  5.  
  6.   var employee = Ext.data.Record.create([
  7.       {name:'firstname'},
  8.       {name:'lastname'}]);
  9.  
  10.   //var myReader = new Ext.data.JsonReader({
  11.       //root:"root"
  12.       //},employee);
  13.  
  14.   var store = new Ext.data.JsonStore({
  15.             id:'ID'
  16.             ,root:'root'
  17.             ,totalProperty:'totalCount'
  18.             ,url:'test.php'
  19.             ,autoLoad:true
  20.             //,reader:myReader
  21.             //,baseParams:{mod:'data',act:'getAllData'}
  22.             ,fields:[
  23.                     {name:'firstname', type:'string'}
  24.                     ,{name:'lastname', type:'string'}
  25.                 ]
  26.             });
  27.  
  28.   alert("Before Displaying");
  29.   var n = store.getTotalCount();
  30.   alert(n);
  31.  
  32.   var myPanel = new Ext.grid.GridPanel({
  33.          store: store
  34.          ,columns:[{
  35.                 dataIndex:'firstname'
  36.                 ,header:'First Name'
  37.                 ,width:145
  38.                 ,sortable:true
  39.                     },{
  40.                 dataIndex:'lastname'
  41.                 ,header:'Last Name'
  42.                 ,width:145
  43.                 ,sortable:true
  44.                      }
  45.              ],
  46.          viewConfig: {
  47.                 autoFill: true,
  48.                 forceFit: true  
  49.             },
  50.  
  51.         listeners: 
  52.          {
  53.             render: function(grid)
  54.             {
  55.                 grid.store.load();
  56.             }
  57.          }
  58.   });
  59.  
  60.   //store.load({params:{firstname:'Vibha',lastname:'Bhagath'}});
  61.  
  62.   var myWindow = new Ext.Window({
  63.         width:300,
  64.         height:300,
  65.         layout:'fit',
  66.         closable:false,
  67.         resizable:false,
  68.         items:[myPanel]
  69.      });
  70.  
  71.    myWindow.show();
  72.  
  73. });
test.php file:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. $o = array(
  4.    "success" => true,
  5.    "records" => array( {"firstname" => "Vibha" ,
  6.                     "lastname" => "Bhagath"},{"firstname" => "Santu" ,
  7.                     "lastname" => "Sapi"},{"firstname" => "Shivoo" ,
  8.                     "lastname" => "Koteshwar"})
  9.    );
  10. $_SESSION["err"] = isset($_SESSION["err"]) ? !$_SESSION["err"] : true;
  11. header("Content-Type: application/json");
  12. print(json_encode($o));
  13. ?>
Apr 20 '10 #1
3 14713
Atli
5,058 Expert 4TB
Hey.

The PHP code you are using is invalid.

The arrays should be valid PHP arrays, not JSON formatted objects. The json_encode function handles the conversion later.

More specifically, the "firstname" and "lastname" groups are invalid. They are JSON formatted, which is not valid PHP syntax. You need to re-format them as valid PHP arrays.
Apr 20 '10 #2
how to make them php formattes array Atli.... I'm a newbie... Dont know how to make it. Can you provide me with some example or tutorial for this?
Apr 20 '10 #3
Atli
5,058 Expert 4TB
You could start by reading the manual entry for arrays. That should get you started.

But, simply put, PHP arrays start with the word "array" followed by a list of variables that the array is made up of, enclosed in parenthesis.
For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $myArray = array( 'value 1', 'value 2', 'value 3' );
  3. echo $myArray[0]; // value1
  4. echo $myArray[1]; // value2
  5. echo $myArray[2]; // value3
  6. ?>
You can specify keys for the array elements by adding them in front of the value, separated by a the => operator.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $myArray = array( 
  3.     'first' => 'value 1', 
  4.     'second' => 'value 2', 
  5.     'third' => 'value 3' 
  6. );
  7.  
  8. echo $myArray['first']; // value1
  9. echo $myArray['second']; // value2
  10. echo $myArray['third']; // value3
  11. ?>
Because arrays are, themselves, PHP variables, array elements can be other arrays. This makes the array multidimensional.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $myArray = array(
  3.     'first' => array( '1x1', '1x2' ),
  4.     'second' => array( '2x1', '2x2' )
  5. );
  6. echo $myArray['first'][0]; // 1x1
  7. echo $myArray['first'][1]; // 1x2
  8. echo $myArray['second'][0]; // 2x1
  9. echo $myArray['second'][1]; // 2x2
  10. ?>
And there is (virtually) no limit how many arrays you can nest inside another array. You could, for example, do this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $myArray = array(
  3.     '2009' => array( // Year
  4.         '01' => array( // Month
  5.             '01' => array( // Day
  6.                 '00' => array( // Hour
  7.                     '00' => array( // Minute
  8.                         // Seconds
  9.                         '01' => 'First second into 2009',
  10.                         '02' => 'Second second into 2009',
  11.                         '03' => 'Third second into 2009'
  12.                     ),
  13.                     '01' => array(
  14.                         '01' => 'Sixty first second into 2009',
  15.                         '02' => 'Sixty second second into 2009',
  16.                         '03' => 'Sixty third second into 2009'
  17.                     )
  18.                 )
  19.             )
  20.         )
  21.     )
  22. );
  23. ?>
You need to make your array fit into this syntax, or the PHP code won't execute and only give you an error.
Apr 20 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Bruce A. Julseth | last post by:
When I execute this SQL statement in my PHP code, I get an error "File '.\Address.txt' not found (Errcode: 2)" $File = addslashes(".\Address.txt"); $SQL = "Load Data InFile \"" . $File . "\"...
0
by: Donald Tyler | last post by:
Then the only way you can do it that I can think of is to write a PHP script to do basically what PHPMyAdmin is trying to do but without the LOCAL in there. However to do that you would need to...
1
by: Ray in HK | last post by:
What are the differences between LOAD DATA INFILE and LOAD DATA LOCAL INFILE ? I found some web hosting company do not allow using LOAD DATA INFILE but allow LOAD DATA LOCAL INFILE. The reason...
1
by: Uthuras | last post by:
Greetings, Machine : Pentium IV Os Windows 2000 server Product : DB2 UDB Release : 7.2 We are fail to load the following data file format into db2 database table that has long varchar...
3
by: subaga | last post by:
Hi, I have to load data into a table with one of the columns defined as NOT NULL, but the file does not have data for it. i would like to load a constant value for this column and the constant...
3
by: nsh | last post by:
mailing.database.mysql, comp.lang.php subject: does "LOAD DATA" EVER work?!? I've tried EVERYTHING! version info: my isp is running my web page on a linux box with php ver. 4.4.1 according to...
1
by: Freedolen | last post by:
Hi, I have checked with some sample data and found inserting of data using 'insert command' takes more time than using 'load data' command to load data from another file. What is the process...
0
by: lanesbalik | last post by:
hi all, right now i'm trying to migrate from db2 running under linux to mysql v5.1. i manage to export out the db2 structure & data into a del (ascii) file. but when i try to load the data...
1
by: John Nagle | last post by:
Is it possible to feed data into a LOAD DATA command in MySQL without writing out the data to a file? It's possible to do this using the MySQL command line and a UNIX FIFO, but that's kind of...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.