Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2004
    Posts
    313

    PHP Array into AMS?

    Hi All,

    Is it possible to somehow load a PHP Array in to AMS and use that Array?

    Thanks

  2. #2
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    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

  3. #3
    Join Date
    Jul 2004
    Posts
    313
    Thanks again Tigg,

    Wow didn't even see that concat!


  4. #4
    Join Date
    Jan 2007
    Posts
    56
    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:

    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);
    ?>
    Or, In The PHP Script Above For An Table Array:

    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";
    In your AMS Program, You Might Do Something Like This:

    Code:
    HTTP.Download( "http://www.domain.com/lua/data.lua", _TempFolder.."\\data.lua", MODE_TEXT, 20, 80, nil, nil, nil );
    dofile( _TempFolder.."\\data.lua" );
    You may also want to remove the data.lua file from your server after you
    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.

  5. #5
    Join Date
    Jul 2004
    Posts
    313
    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?

    Code:
    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");
    Thanks
    Last edited by ianhull; 02-21-2007 at 10:12 PM.

  6. #6
    Join Date
    Jan 2007
    Posts
    56

    Thumbs up

    A couple of ways that I can think of.

    1) Get sside's WebBrowser thingy he just released, and do something like this:
    Code:
    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);
    You'll need to add an Application.Sleep because it will take a few milliseconds
    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.

  7. #7
    Join Date
    Jul 2004
    Posts
    313
    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

Similar Threads

  1. PHP explode array function
    By azmanar in forum AutoPlay Media Studio 6.0
    Replies: 2
    Last Post: 03-06-2006, 12:01 PM
  2. Mysql, PHP results display in AMS?
    By yss in forum AutoPlay Media Studio 5.0
    Replies: 8
    Last Post: 05-23-2005, 10:02 AM
  3. Replies: 6
    Last Post: 12-01-2004, 12:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts