View Full Version : flash mx2004 php
amjad
March 30th, 2004, 06:30 AM
hi all
as i'm a new comer in flash
so i've know idea about flash that how 2 connect flash 2 mysql using php
i've enough knowledge of php but
i dont know how 2 use this, on flash as a front end php-mysql tool,
can anyone plz help me,
i want 2 retrive, insert, delete and update data from flash to mysql
any suggession would be apperciated
thanks
amjad
kill.robot.kill
March 30th, 2004, 11:09 AM
you need to think of flash kinda like a static html form page. Anything you want to do is going to have to be set up in flash, but executed in php, and then sent back to flash. Flash can really only set up variables to be sent, returned and manipulated (similar to a html form), but a php page will end up having to do all the work, which is good that you have some php knowledge.
Say you wanted to set up a form mailer.
flash
on (release) {
sender_mail = _root.Semail.text
sender_name = _root.Sname.text
sender_subject = _root.Ssubject.text
sender_message = _root.Smessage.text
loadVariables("sendmail.php",this,"POST");
}
if(!empty($HTTP_POST_VARS['sender_mail']) || !empty($HTTP_POST_VARS['sender_message']) || !empty($HTTP_POST_VARS['sender_subject']) || !empty($HTTP_POST_VARS['sender_name']))
{
$to = "receipent@webhost.com";
$subject = stripslashes($HTTP_POST_VARS['sender_subject']);
$body = stripslashes($HTTP_POST_VARS['sender_message']);
$body .= "\n\n---------------------------\n";
$body .= "Mail sent by: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";
$header = "From: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";
$header .= "Reply-To: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";
$header .= "X-Mailer: PHP/" . phpversion() . "\n";
$header .= "X-Priority: 1";
if(@mail($to, $subject, $body, $header))
{
echo "output=sent";
} else {
echo "output=error";
}
} else {
echo "output=error";
}
the code in these examples isn't the best, its just the quickest example I could find.
say you wanted to list the recordsets of a database, in flash all you have to do is set up a textbox,
but in php you have to do the meat of the work, something like this
/* Build SQL query to fetch all entries from the table */
$query = "SELECT * FROM $table ORDER BY entryDate DESC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
$entryDate = strftime("%A %d/%m/%y", $row['entryDate']);
$list .= "<b>Date:</b> " . $entryDate . "<br>";
$list .= "<b>Name:</b> " . $row['name'] . "<br>";
$list .= "<b>Email:</b> " . $row['email'] . "<br>";
$list .= "<b>city:</b> " . $row['city'] . "<br><br>";
}
/* Output data in required format */
print "&list=" . urlencode($list) . "&";
In flash you would just have to handle the variable 'list', but as you can see php did all the work.
While these examples have been pretty simple you can see that flash did very little work and php did
the majority of the work. Which is why, if you understand php and mysql you will have no
problem integrating into your flash movies. But if you don't know any php you will struggle.
good luck
amjad
March 31st, 2004, 12:20 AM
thanx robot i'll try this one, then i'll reply you again
amjad
April 1st, 2004, 07:26 AM
thanx robot
thats a pretty nice example for beginner
but i always did php work in a html page.
as u use flash with php, same we use with html, so here you spouse you have 30 records in mysql (any table), when we try to retrieve in a html page we simply write a while loop before the <tr> tag and ends after </tr> tag, as below
Note am not a very experienced person in php but just a little know about php
<? while($rows = mysql_fetch_array($result)){?>
<tr class="admin3">
<td><? echo $rows["Organization_Name"]?></td>
<td><? echo $rows["Description"]?></td>
</tr>
<? }
mysql_free_result($result);
?>this loop execute 30 time coz there are 30 rows in table so 30 rows appears on front of html page easily, in that particular case it is very easy 2 do (this will be done in a same php file)
but when we move to flash how could we get the same results in flash, coz flash is a different file which publish another html file and our php code is in an another php file
thats what i want 2 said and want 2 get solution of this coz i want 2 populate data in flash (on datagrid, comboxes, textarea and etc)
do u got the point i wat i said?
thnas
amjad:q: :q:
kill.robot.kill
April 1st, 2004, 11:10 AM
well first off, flash doesn't accept an array from php, it will only accept a string. No integers, no arrays, only strings. So you will have to craft your variables to set them up like a string, and them seperate them out in flash to make them an array, or just handle them differently in php so you don't run into that problem.
this was posted in the code above, but it does what you are asking about.
while($row = mysql_fetch_array($result)) {
____$entryDate = strftime("%A %d/%m/%y", $row['entryDate']);
________
___$list .= "<b>Date:</b> " . $entryDate . "<br>";
____$list .= "<b>Name:</b> " . $row['name'] . "<br>";
____$list .= "<b>Email:</b> " . $row['email'] . "<br>";
____$list .= "<b>city:</b> " . $row['city'] . "<br><br>";
}
/* Output data in required format */
print "&list=" . urlencode($list) . "&";
It loops through the database and for each time it receives a database row it adds to the $list variable. Basically when you are done you are going to have one very long string that looks like this.
&list=%3Cb%3EDate%3A%3C%2Fb%3E+Thursday+01%2F04%2F0 4%3Cbr%3E%3Cb%3EName%3A%3C%2Fb%3E+%3Cbr%3E%3Cb%3EE mail%
kill.robot.kill
April 1st, 2004, 11:19 AM
yours may look something like this:
while($rows = mysql_fetch_array($result)){
$list .= "<b>Organization_Name:</b> " . $rows["Organization_Name"]."<br>";
$list .= "<b>Description:</b> " . $rows["Description"]."<br><br>";
}
/* Output data in required format */
print "&list=" . urlencode($list) . "&";
Ok, this isn't tested so it may not work properly the first time. anyways you send that to flash, and it will dump all the data into one long text box. you can just put a text box called 'list' in your flash movie, and after flash has properly loaded the data from the php page it will show up.
amjad
April 2nd, 2004, 07:09 AM
thanx again robot
that works but that return me only last single row from table, but there are 10 rows in my table.
I building a list of organization. My table has 3 columns (id, orgName, Des) How do I get each organization and its description in flash?
my php code Something like this...
include ("connection.php");
$query = "select Organization_Name, Description from ecards";
$result = mysql_query($query);
while($rows = mysql_fetch_array($result)){
$list = "<b>Name : </b>" .$rows["Organization_Name"];
$list .= "<b>Description : </b>" .$rows["Description"] ."<br>";
}
print "&list=" . urlencode($list) . "&";
and flash code
var loadphp = new LoadVars();
loadphp.onLoad = function(success){
if(success){
list = this.list;
}
}
loadphp.load("test.php");
wat should i do 2 get the complete data from db
thanx
amjad
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.