# How can i format records in flash mx coming from mysql

**URL:** <https://forum.kirupa.com/t/how-can-i-format-records-in-flash-mx-coming-from-mysql/80591>\
**Category:** Uncategorized\
**Created:** [February 23, 2005, 7:29am UTC](https://forum.kirupa.com/t/how-can-i-format-records-in-flash-mx-coming-from-mysql/80591 "2005-02-23T07:29:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![olm75](https://avatars.discourse-cdn.com/v4/letter/o/8c91f0/32.png) [@olm75](https://forum.kirupa.com/u/olm75)\
**Post date:** [February 23, 2005, 7:29am UTC](https://forum.kirupa.com/t/how-can-i-format-records-in-flash-mx-coming-from-mysql/80591/1 "2005-02-23T07:29:37Z")

</div>

ok i have results from my mysql coming to flash mx and im trying to format it in rows like:

VENUENAME ADDRESS PHONENUMBER  
VENUENAME ADDRESS PHONENUMBER  
VENUENAME ADDRESS PHONENUMBER  
VENUENAME ADDRESS PHONENUMBER

and i want about 10 records to show in flash at a time…  
here is the actionscript and the PHP code:

// Create another LoadVars instance to receive the server’s reply  
replyData = new LoadVars();

// Specify a function to call when this new instance receives the reply.  
replyData.onLoad = handleReply;  
// Submit the order data  
formData.sendAndLoad(submitURL, replyData, ‘POST’);  
// Tell the user what’s happening.  
message\_txt.htmlText = “Submitting search, please wait…”;  
}  
function handleReply(success) {  
if (success) {  
message\_txt.htmlText = “Your search was received:”+chr(10)+chr(10);  
for(var i = 0; i \< Number(replyData.totalNum); i++) {  
if(replyData[‘url’+i] != undefined && replyData[‘url’+i] != ‘’) {  
message\_txt.htmlText += “Venue Name: \<a href=’”+replyData[‘url’+i]+"’ target=’\_blank’\>" + replyData[‘venueName’+i]+"\</a\>"+newline;  
} else {  
message\_txt.htmlText += "Venue Name: "+replyData[‘venueName’+i]+newline;  
}  
message\_txt.htmlText += "Address: " + replyData[‘address’+i] + newline;  
message\_txt.htmlText += "City: " + replyData[‘city’+i] + newline;  
message\_txt.htmlText += "State: " + replyData[‘state’+i] + newline;  
message\_txt.htmlText += "Zip Code: " + replyData[‘zipCode’+i] + newline;  
message\_txt.htmlText += "Area Code: " + replyData[‘areaCode’+i]+chr(10);  
message\_txt.htmlText += "Phone: " + replyData[‘phoneNumber’+i]+chr(10);  
message\_txt.htmlText += “\<br\>”;  
}

} else {  
message\_txt.htmlText = “There was a problem submitting your search. The server may be down or not responding.”;  
}  
}

this shows records like this:  
VENUENAME  
ADDRESS  
PHONENUMBER

VENUENAME  
ADDRESS  
PHONENUMBER

VENUENAME  
ADDRESS  
PHONENUMBER

NEED TO CHANGE IT…CAN ANYONE HELP, here’s the PHP

// MySQL connection  
$server = ‘localhost’;  
$username=“nigolmvc”;  
$password=“oscarlm4675”;  
$database=“nigolmvc\_nightspotz”;  
//$tbl=“venues\_test”;  
$tbl=“venues”;  
//  
// Purely for detecting if a $\_POST value was passed successfully  
$tripwire = 0;  
$tmp = array();  
$err = array();  
// List of variable names to be passed from Flash. Used in assembling the query.  
// Delimited this to just the venueName for now, because I don’t know how the combo boxes will pass data.  
// \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
$postList = array(‘venueName’,‘venueType’,‘address’,‘city’,‘state’,‘areaCode’,‘ageGroup’);  
// \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

// This for() loop _should_ cycle through the $\_POST variables looking for matches based on the values  
// contained inside the $postList array, and assemble the query based on positive matches.  
// I’ve set the incoming datatype to $\_GET rather than $\_POST for testing purposes; you can run mock  
// tests in the browser window like so:  
// [http://www.nightspotz.com/test\_search2/search.php?name=nacional](http://www.nightspotz.com/test_search2/search.php?name=nacional)  
// [http://www.nightspotz.com/test\_search2/search.php?city=los](http://www.nightspotz.com/test_search2/search.php?city=los) angeles  
// Just make sure to switch it back to $\_POST when you prep this file for Flash usage.  
for($i = 0; $i \< count($postList); $i++) {  
$tmp[$tripwire][‘var’] = $postList[$i];  
if(isset($\_POST[$postList[$i]])) {  
//if(isset($\_GET[$postList[$i]])) {  
$tmp[$tripwire][‘val’] = $\_POST[$postList[$i]];  
//$tmp[$tripwire][‘val’] = $\_GET[$postList[$i]];  
$tripwire++;  
} else {  
$tmp[$tripwire][‘val’] = ‘\<null\>’;  
}  
}

// Query assembly  
$query = ‘SELECT \* FROM ‘.$tbl;  
// If any of the $\_POST data is _not_ blank…  
if($tripwire \> 0) {  
$query .= ’ WHERE ‘;  
for($w = 0; $w \< $tripwire; $w++) {  
if($tmp[$w][‘var’] !== ‘venueName’) {  
$query .= $tmp[$w][‘var’].’ = "’.$tmp[$w][‘val’].’"’;  
} else {  
// The % signs are a wildcard character for searches in MySQL. It helps for partial name searches.  
$query .= $tmp[$w][‘var’].’ LIKE “%’.$tmp[$w][‘val’].’%”’;  
}  
if($w \< ($tripwire - 1)) { $query .= ’ AND '; }  
}  
}  
$query .= ’ ORDER BY '.$postList[0];

// Connect to server and execute query  
mysql\_connect($server,$username,$password) or die(‘error0=’.mysql\_error());  
@mysql\_select\_db($database) or die(‘error1=’.mysql\_error());  
$result = mysql\_query($query) or die(‘error2=’.mysql\_error());  
$tempNum = mysql\_num\_rows($result);  
mysql\_close();

// parse data for Flash  
$out = ‘qry=’.rawurlencode($query).’&’;  
for($i = 0; $i \< $tempNum; $i++) {  
$out .= ‘venueName’.$i.’=’.rawurlencode(mysql\_result($result,$i,“venueName”)).’&’;  
$out .= ‘venueType’.$i.’=’.rawurlencode(mysql\_result($result,$i,“venueType”)).’&’;  
$out .= ‘city’.$i.’=’.rawurlencode(mysql\_result($result,$i,“city”)).’&’;  
$out .= ‘state’.$i.’=’.rawurlencode(mysql\_result($result,$i,“state”)).’&’;  
$out .= ‘address’.$i.’=’.rawurlencode(mysql\_result($result,$i,“address”)).’&’;  
$out .= ‘areaCode’.$i.’=’.rawurlencode(mysql\_result($result,$i,“areaCode”)).’&’;  
$out .= ‘ageGroup’.$i.’=’.rawurlencode(mysql\_result($result,$i,“ageGroup”)).’&’;  
$out .= ‘url’.$i.’=’.rawurlencode(mysql\_result($result,$i,“url”)).’&’;  
}  
// A number you can use in a for() loop inside FlashMX when retrieving data.  
$out .= ‘totalNum=’.$tempNum.’& ‘;  
echo $out;  
// Temporary output to a temp file for testing purposes.  
//writeToFile(’./!!!SEARCH\_OUTPUT.txt’, ‘…/’, rawurldecode($out));

//////////////////////////////////////////////////////////////////////////////////////////////  
// PRIVATE  
//////////////////////////////////////////////////////////////////////////////////////////////  
// This is here just so I can see what the PHP file is outputting…  
// Write contents to file  
function writeToFile($path, $parent, $data) {  
// You don’t _have_ to use this, but it’s here for posterity’s sake  
global $err;  
$old = umask(0);  
chmod($parent, 0777);  
if(file\_exists($path)) { chmod($path, 0777); }  
if(!$handle = fopen($path, ‘w+b’)) {  
$err[] = ‘Cannot open file ‘.$path.’.’;  
break;  
}  
rewind($handle);  
if(fwrite($handle, $data) === false) {  
$err[] = ‘Cannot write to file ‘.$path.’.’;  
break;  
}  
fflush($handle);  
ftruncate($handle, ftell($handle));  
fclose($handle);  
umask($old);  
}  
?\>
