PDA

View Full Version : Help About Parameter



reang
27 Mar 2007, 11:58 PM
Hi All...

I have parameter in javascript, now i want to use this in query SQL on PHP.
for example :



in JS :
var params ='abc';

and in Query PHP :

$query = "SELECT * FROM tblABC where id =' params '";

note : in one file.


please help me....

regards.

KimH
28 Mar 2007, 6:01 AM
Are you trying to run JavaScript and PHP from within the same program???? :?

If you are.... don't! At least.... my guess is that this is not what you should do in this situation. It can be done but... well... that is a very different approach.

What you need is to pass the JS variable from the HTML/JavaScript page that is loaded in the browser by the user into a query string or post back to the server where the PHP will get it and use it to build the SQL.... and then return some result back to the client.

.... or am I missing something???

reang
28 Mar 2007, 7:08 AM
I write code in one file.

And i want to convert javascript variable to PHP.

any idea?

regards.

dfenwick
28 Mar 2007, 7:25 AM
I write code in one file.

And i want to convert javascript variable to PHP.

any idea?

regards.

You're mixing where things are running. Unless you have a javascript enabled server, the javascript is running on the client. Your PHP code will be parsed and executed on the server with the output of that parsing delivered to the client.

In order to provide what you're trying to do, you're going to have to do an asynchronous call back to the server and pass the javascript variable back to your PHP application. This is moderately simple to do, and your call can even be to the same PHP file. It would go something like this:

Browser requests myscript.php
myscript.php parses itself and delivers basic content + javascript back to the browser
the javascript executes and a variable gets set
When the variable is set, the javascript asynchronously calls 'myscript.php?params='+params
myscript.php sees that there's a $_REQUEST['params'] and then executes the query

But it requires 2 requests to the web server. There's no easy way around that.

reang
28 Mar 2007, 8:14 AM
thank's friends.

ok this my code :

for the first :


echo "<area shape='poly' coords='$dtMAP[1]' href='$sldurl/frontdlg.php?obj=$dtMAP[2]&name=$line[0]' target='frm' $_POST ['param=GD'];
onclick='javascript:infDlg.showDialog(\"".$dtMAP[Icon_Name]." ".$line[0]."\",\"".$dtMAP[Icon_Name]."\")'>"; //======(1)


And i call this in BasicDialog :


.........................
.........................
.........................
showDialog : function(dtitle,dparams){ //======== (2)
var dlgmenu;
if(!dialog){ // lazy initialize the dialog and only create it once
dialog = new Ext.LayoutDialog("inf-dlg", {
width:760,
height:495,
minWidth:10,
minHeight:10,
autoTabs:true,
modal:true,
shadow:true,
autoScroll:false,
proxyDrag: true,
fitToFrame:true,
fixedcenter: true,
//closable:false
north: {
split:false,
titlebar: false,
alwaysShowTabs: false,
//hideTabs:true,
initialSize: 25,
tabPosition: 'top',
cmargins: {top:0,bottom:0,right:0,left:0}
},
west: {
split:true,
initialSize: 150,
minSize: 150,
maxSize: 250,
titlebar: true,
collapsible: true,
animate: true
},
center: {
autoScroll:false,
tabPosition: 'top',
closeOnTab: false,
alwaysShowTabs: false
}
});
dialog.addKeyListener(27, dialog.hide, dialog);
dialog.addButton('Tutup', dialog.hide, dialog);

var layout = dialog.getLayout();
layout.beginUpdate();

layout.add('north', new Ext.ContentPanel('dlgnorth', {title: 'Sub Menu'}));
layout.add('center', new Ext.ContentPanel('center', {fitToFrame:true}));
layout.endUpdate();

createtoolbar();
}

sparams=dparams; //========= (3)

dialog.setTitle('Info '+dtitle);
dialog.show(showBtn.dom);

function createtoolbar(){
<?php
$sqldlgmenu="SELECT menu_id, menu_type, menu_name, menu_link, menu_params FROM tblMenus WHERE (menu_parent = 0) AND (menu_type = N'dlgsldmenu')";
$rsdlgmenu=mssql_query($sqldlgmenu);
while ($dlgmenu=mssql_fetch_array($rsdlgmenu)){
?>
var <?php echo $dlgmenu[menu_type].$dlgmenu[menu_id]; ?> = new Ext.menu.Menu({
id: 'sldmenu',
items: [
<?php
$sqldlgitemmenu="SELECT menu_id, menu_type, menu_name, menu_link, menu_params FROM tblMenus WHERE (menu_parent = $dlgmenu[menu_id]) ";
$rsdlgitemmenu=mssql_query($sqldlgitemmenu);
while ($dlgitemmenu=mssql_fetch_array($rsdlgitemmenu)){
echo "new Ext.menu.Item({text: '".$dlgitemmenu[menu_name]."',link:'".$dlgitemmenu[menu_link]."',handler: menuItemClick}),";
}
?>
''
]
});

<?php
}

$sqldlgmenu="SELECT menu_id, menu_name, menu_type FROM tblMenus WHERE (menu_parent = 0) AND (menu_type = N'dlgsldmenu') AND menu_params='<place sparams on here> '"; //========== (4)
$rsdlgmenu=mssql_query($sqldlgmenu);
?>
var tb = new Ext.Toolbar('dlgtoolbar');
<?php
while ($dlgmenu=mssql_fetch_array($rsdlgmenu)){
echo "tb.add({text:'".$dlgmenu[menu_name]."', menu: $dlgmenu[menu_type]$dlgmenu[menu_id]});";
}
?>
}
)
.........................
.........................
.........................



for note this page not reload, only create menu from table where menu_params = sparams.


regards.