PHPJavascript

Web Development Guide – My Personal Library of Tutorials and Scripts

Flash xml sendAndLoad from and to data with PHP and MYSQL

September21

This a simple example to demonstrate how to use sendAndLoad function to send data from flash to xml and then xml to flash.

Actionscript coding style is different from our usual PHP coding, it follows OOPs concept classes and all but the syntax the scenario for me is different. So here I am trying to give working example hoping that it would help beginners when they are stuck and then after hours of torture realize it was a basic error.

This is a section from a website code I am developing currently. Here I am displaying articles with ‘title’, ’short description’ with a readmore button when a user clicks on the readmore an new window opens with detailed description of the article. I output data from mysql table using XML.

Summary

  1. User clicks on readmore
  2. ‘articleID’ is send to ‘page1.php’
  3. mysql table poetry searches for row where ‘id=articleID’
  4. description  is send back to flash

MYSQL Database part

Donwload 94.rar from the top of the page and open file poetry.sql to get the DB structure

Flash part

var myVars = new XML();
myVars.ignoreWhite = true;
myVars.onLoad = function(success){
if (success) {
myRecord1=myVars.firstChild.childNodes;
_root.TM_title = myRecord1[0].firstChild;
_root.pageTitle = myRecord1[0].firstChild;
_root.pageTxt = myRecord1[1].firstChild;
} else {
trace("Loading Error");
}
}
myVars.sendAndLoad("page1.php?id="+this._parent.articleID, myVars);

page1.php

<?php
$link = mysql_connect("localhost","root","");
mysql_select_db("work");
$id = $_GET["id"];

$sql = "SELECT * FROM poetry where id=" . $id;
$result = mysql_query($sql) or die(mysql_error());
header("Content-type: application/xml");
?>
<news>
<?php
$row = mysql_fetch_array($result);
?><mytitle><?=$row['title']?></mytitle><article id="<?=$row['id']?>"><?=$row['text']?></article>
</news>

This is just a section and will not probably when you copy paste, so I have attached the whole thing on the top of this page download it and work on it. But make sure you test it on a browser

posted under Flash

Email will not be published

Website example

Your Comment:

 

2,885 spam comments
blocked by
Akismet