need help withformatting records in flash mx from mysql

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   need help withformatting records in flash mx from mysql
olm75
CZ Newbie
olm75 has been a member for over 20 year's 20 Year Member
Status: Offline
Joined: Dec 05, 2004
0.00 posts per day
Posts: 10
Points: 621
   
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:
// [ Register or login to view links on this board. ]
// [ Register or login to view links on this board. ] 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);
}
?>



Back to top Reply with quote
#2   re: need help withformatting records in flash mx from mysql
bpat1434
CZ Newbie
bpat1434 has been a member for over 19 year's 19 Year Member
usa.gif maryland.gif
Occupation: EMT, Community Assistant, Webmaster, Firefighter, Web Host
Age: 40
Gender: Male
Website:
Status: Offline
Joined: Jan 19, 2005
0.00 posts per day
Posts: 21
Points: 783
AIM Address Yahoo Messenger MSN Messenger 
Perhaps what I see as a problem is this:

+newline

on each end of your Flash code. Why is it there? What happens when you take it away?

~Brett



Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum