Hi All,
Is it possible to somehow load a PHP Array in to AMS and use that Array?
Thanks
Professional Software Development Tools
Hi All,
Is it possible to somehow load a PHP Array in to AMS and use that Array?
Thanks
Just have your PHP script return a concatenated string to AMS and you can then use Table.Concat to format that string into a table.
Or you could have PHP return the formating of a table so when it sets the variable used in HTTP.Submit it will format it as a table. Maybe, I would have to play with it.
Tigg
TJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
Thanks again Tigg,
Wow didn't even see that concat!
![]()
Something else I wanted to add here since this is a fresh post, I keep
forgetting to respond every time I see this subject come up, is that you can
have your PHP scripts (or any other web language/scripts for that matter)
write out whatever you need to the screen, and have your AMS program read
it in.
In other words, let's say you have a lot of info to pass back to your program,
you can have your PHP script write it out to the screen as Lua code, and
have your AMS program read it in, variables and all.
I had a program I was working on a little while ago do this very thing so I
could grab data from my database. It was one of my first programs while I
was testing out AMS and looking at the possibilities.
You could have your app read in the info, maybe create a temporary file on
your system, and then read it in with the Lua dofile() function or whatever.
The reason I ended up buying AMS and using it more than I will ever use my
copy of Visual Basic Dot NET is because of the Lua scripting! Man is it cool
and fast, and works extremely well for stuff like this.
I can also create these unbelievable programs in a matter of minutes, and in
Visual Basic, it would have taken me hours to create the same thing.
Anyway, you could do something like this:
Or, In The PHP Script Above For An Table Array:Code:<?php //Connect to database - prints 1 if connect fails and prints 2 if DB select fails mysql_connect ($dbhost, $dbuser, $dbpasswd) OR DIE ('1'); mysql_select_db ($dbname) OR DIE ('2'); $q1 = "SELECT * FROM DB_Table WHERE DB_Some_Field = '$_POST[VarFromAMSProgram]'"; $r1 = mysql_query($q1) OR DIE ('3'); $a1 = mysql_fetch_array($r1); //Add DB data to AMS/Lua variables $data = "sVar1ForAMSProgram = \"Here Is Some Data ".$a1[Field_Info1_You_Want]."\";\r\n"; $data .= "sVar2ForAMSProgram = \"Here Is Some More Data ".$a1[Field_Info2_You_Want]."\";\r\n"; //write the DB data to a file $file = "lua/data.lua"; $handle = fopen($file, 'w'); fwrite($handle, $data); fclose($handle); ?>
In your AMS Program, You Might Do Something Like This:Code://Add DB data to variable $data = "sVarForAMSProgram = {}"; $data .= "sVarForAMSProgram.data1 = \"Here Is Some Data ".$a1[Field_Info1_You_Want]."\";\r\n"; $data .= "sVarForAMSProgram.data2 = \"Here Is Some More Data ".$a1[Field_Info2_You_Want]."\";\r\n";
You may also want to remove the data.lua file from your server after youCode:HTTP.Download( "http://www.domain.com/lua/data.lua", _TempFolder.."\\data.lua", MODE_TEXT, 20, 80, nil, nil, nil ); dofile( _TempFolder.."\\data.lua" );
receive the needed information from it so others cannot access it.
This type of thing also works really, really well for doing "live" program updates
for your customer/client software, the possibilities are really endless.
This is just one of many ways you can handle this type of situation. There's
prettier and there's uglier. Hope that helps for future ideas. Sorry, I didn't
mean to carry on like this, I just love this application.
Patrick
Last edited by coderanger; 02-21-2007 at 06:58 PM.
WOW Patrick,
Excellent stuff!
Man am I going to have some fun with this
Would it be possible to open the php file from the server without creating and downloading a .lua file?
ThanksCode:HTTP.Download( "http://www.domain.com/lua/data.lua", _TempFolder.."\\data.lua", MODE_TEXT, 20, 80, nil, nil, nil ); dofile( _TempFolder.."\\data.lua" ); //Change to something like result = TextFile.ReadToString("http://www.domain.com/my.php");
Last edited by ianhull; 02-21-2007 at 10:12 PM.
A couple of ways that I can think of.
1) Get sside's WebBrowser thingy he just released, and do something like this:
You'll need to add an Application.Sleep because it will take a few millisecondsCode:WebBrowserWindow.SetUrl("http://www.domain.com/lua/data.html"); Application.Sleep(200); result = WebBrowserWindow.GetTextContent(); --result contains your string. You can view it in a message popup for testing.. Dialog.Message("Notice", result, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
to read your string in, otherwise, you'll most likely get an error or worse, a
crashed program. You will also have to change your data filename to .html
extension.
OR, A MUCH BETTER SOLUTION:
You might want to use Worms "GetUrlSrc.dll" and read it in that way. I think
it's a much better solution than that above, but the other will work in a pinch.
See this for Worms cool dll:
http://www.indigorose.com/forums/sho...ad+file+server
One last option would be to connect and get your info directly from your MySQL
database. Again, endless solutions. I wish all of my other programming tools offered
so many solutions.
Patrick
P.S. Funny thing is, it was a post that you posted and Worm responded to for
just this type of thing.. he he he
Last edited by coderanger; 02-21-2007 at 11:56 PM.
Oh My Gawd,
This is absolutley fantastic,
This little piece of code allows me to connect to a web server, send variables/values wait for a response, write out lua variables suitable for AMS and pass and play with the results vars in AMS woo hoo.
I really like it.
Code:ClickHTTPReq = luacom.CreateObject("WinHttp.WinHttpRequest.5.1") if not ClickHTTPReq then return end vars = "ian"; ClickHTTPReq:Open("GET", "http://localhost/lua/index.php?fname=".. vars, 0) ClickHTTPReq:Send(); if ClickHTTPReq.Status ~= 200 then return end s = ClickHTTPReq.ResponseText Dialog.Message("Notice", s, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
lol yes, I remeber that post but thought it was just for text files. haha