|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
trying to format records in flash mx coming from mysql
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','st ate','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_sear...p?name=nacional // http://www.nightspotz.com/test_sear...ch.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($resu lt,$i,"venueName")).'&'; $out .= 'venueType'.$i.'='.rawurlencode(mysql_result($resu lt,$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($resul t,$i,"areaCode")).'&'; $out .= 'ageGroup'.$i.'='.rawurlencode(mysql_result($resul t,$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); } ?> |
![]() |
| Viewing: Dev Articles Community Forums > Web Design > Flash Development > trying to format records in flash mx coming from mysql |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|