PDA

View Full Version : Tabpanel autoload php with mysql into a new tab?



sutee84
28 Dec 2010, 2:03 AM
Hi!

I'm new here, and also new to ExtJs.
I tried to upgrade my webpage with Ext, and I figured, that I make a viewport, a menu at north, info at west, and the main contains at the center. I made everything, but I put a tabpanel at center, and I want that if I click a menu entry at the top, then the selected page load into a new tab at the center. It works well if I use simple html, or pure php without session and without mysql, but I want to use mysql and session also, so I need your help.
The js code on the main page:

Ext.onReady(function()
{
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var tabs = new Ext.TabPanel({
region: 'center',
margins: '0 5 5 0',
activeTab: 0,
enableTabScroll:true,
defaults: {autoScroll:true},
items: [{
contentEl: 'fooldal',
title: 'F?oldal',
closable: false,
autoScroll: true
}]
})
var viewport = new Ext.Viewport({
layout: 'border',
items: [
// create instance immediately
new Ext.BoxComponent({
region: 'north',
height: 48,
contentEl: 'menu'
}), {
region: 'west',
id: 'west-panel',
title: '',
split: false,
width: 205,
minSize: 175,
maxSize: 400,
collapsible: true,
margins: '0 0 5 5',
contentEl: 'west'
},tabs

]
});
/** Add Tab *******************/
function addTab(name,tab_url){
tabs.add({
title: name,
iconCls: 'tabs',
closable:true,
autoLoad: {url:tab_url, scripts: true},
listeners:{
vate : function(panel){
panel.getUpdater().refresh();
}
}
}).show();
}
Ext.get('sajat_beo').on('click',function(){addTab('Saját beosztás','./pages/info2.php');});
});
And the info2.php:

<div>
<?php
session_start();
echo $_SESSION["db"];
$query="SELECT * FROM mozik";
$eredm=mysql_query($query,$_SESSION["db"]);
while($rekord=mysql_fetch_array($eredm))
{
echo $rekord["mnev"]."<br/>";
}


?>
</div>

Condor
28 Dec 2010, 2:15 AM
Doesn't look incorrect.

Can you check what info2.php actually returns (check the Firebug Net tab)?

sutee84
28 Dec 2010, 4:21 AM
I checked, and I get this:

- Answer headers:
Date Tue, 28 Dec 2010 12:17:41 GMT
Server Apache/2.2.16 (Ubuntu)
X-Powered-By PHP/5.3.3-1ubuntu9.1
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma no-cache
Vary Accept-Encoding
Content-Encoding gzip
Content-Length 30
Keep-Alive timeout=15, max=81
Connection Keep-Alive
Content-Type text/html

- Request headers:
Host localhost
User-Agent Mozilla/5.0 (X11; U; Linux i686; hu-HU; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language hu-hu,hu;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-2,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
X-Requested-With XMLHttpRequest
Referer http://localhost/manpower_manager3/main.php
Cookie ys-west-panel=o%3Acollapsed%3Db%253A0; PHPSESSID=96pg5behfav6e4gni0s6hn80j4

- Answer:
<div>
0</div>

- HTML:
0

sutee84
28 Dec 2010, 4:24 AM
The other problem that, when I write the $_SESSION["db"] on the main page I get "Resource id #3", but when I write it on the loaded tab I get "0", so the session doesn't work, and the database connection also doesn't work, and if I trie to connect before the query on info2.php I get "500 Internal Server Error"

Condor
28 Dec 2010, 4:26 AM
And what is wrong with that?

Your server is returning:

<div>
0</div>
so I assume that your "mozik" table only has a single record with "mnev"=0.

sutee84
28 Dec 2010, 4:29 AM
The problem when I put the code of info2.php into a div and use as contentel in a tab, it works (write: Szeged,Veszprém,Debrecen,Alba), but if I autoload it it doesn't work (write nothing).
The mysql_query has to return 4 result, but it return 0.

Condor
28 Dec 2010, 5:43 AM
This is a PHP problem and I'm not a PHP programmer, so this is not really the correct forum to ask this.

The '0' in your output is the result from 'echo $_SESSION["db"];', so I assume you don't have a db in your session yet.

mschwartz
28 Dec 2010, 7:55 AM
I don't think you can store a mysql DB handle in $_SESSION.

PHP serializes the object and writes it to a file (in /tmp or some other directory) when the request is complete. session_start() will read the file and unserialize the object. I am quite sure you can't serialize an object that has an open socket like a mysql DB handle.

sutee84
28 Dec 2010, 8:11 AM
The php code is OK, I think because if I put it into a div and make a tab from the div with contetEl like fooldal in the first source code, it works.
The problem is when I trie to autoload it into the new tab. Somewhy the session, and the mysql_connect doesn't work if I autoload the php file. I tried to load with autoload other php files, what are works good (if I run it in the webbrowser simply or put it into the fooldal div, what is a static tab with contentEl), but they also not work in the autoload tab. First I think it's because of the connection is missing, but when I tried to connect from the autoload file, and not from the main file(what contains the viewport and the tabpanel), I get 500 Internal Server Error. Then I tried to use Session, and that's why I put the db resource into a session variable, but in the autoload page the session also doesn't work:(

mschwartz
28 Dec 2010, 8:17 AM
http://bytes.com/topic/php/answers/164494-socket-session

Your DB handle is roughly equivalent to a socket. The answers in that WWW page are true for DB handles.

I can see your PHPSESSID cookie is being sent, so the session should be proper otherwise.

sutee84
28 Dec 2010, 8:24 AM
And why I get Intenal Server Error when I want to connect to the database from the autoload php?

mschwartz
28 Dec 2010, 8:30 AM
And why I get Intenal Server Error when I want to connect to the database from the autoload php?

Turn on error reporting and view the response in firebug.

sutee84
28 Dec 2010, 8:36 AM
500 Internal Server Error
107ms

Answer headers:
Date Tue, 28 Dec 2010 16:32:25 GMT
Server Apache/2.2.16 (Ubuntu)
X-Powered-By PHP/5.3.3-1ubuntu9.1
Vary Accept-Encoding
Content-Encoding gzip
Content-Length 26
Connection close
Content-Type text/html

Request headers:
Host localhost
User-Agent Mozilla/5.0 (X11; U; Linux i686; hu-HU; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language hu-hu,hu;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-2,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
X-Requested-With XMLHttpRequest
Referer http://localhost/manpower_manager3/main.php
Cookie ys-west-panel=o%3Acollapsed%3Db%253A0; PHPSESSID=96pg5behfav6e4gni0s6hn80j4

Answer:

<div>

sutee84
28 Dec 2010, 8:56 AM
Thanks fo all!
I found the problem, the connection file is in the same folder with the main page, but not with the info2.php, but I included it with the same path, and that was the problem.

mschwartz
28 Dec 2010, 8:58 AM
great