phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Flash Database: Saving Data at Server Side

Tag: flash, database, server side   Category: PHP Application
post: 24 Mar 2008 read: 620


Flash Database Step By Step Tutorial - Part 3: When use vote a choice, flash application will send it to server. Then server will update data (update polling.txt).

This is saving function. Add to polling.php:


function saveData(){
  global $file_data;
  
  
  if(number_format($_GET['num']) < 1) die("registered=false");
  
  // open file
  $fp_array 	= file($file_data);
  $fp 			= fopen($file_data,"r+");

  $temp_string 	= "";
  
  // read file
  foreach($fp_array as $key => $value){
    // extract each lines
	$line 	=	explode('=', $value); 
	$name 	= 	$line[0];
	$val	= 	eregi_replace("\r\n","",$line[1]);
	
	// if as votes
	if(substr($name,0,5)=='votes'){
	  $val	= 	(int)eregi_replace("\r\n","",$line[1]);
	  $match=	(int)(substr($name,5,2));

	  // if the index same as choice, add 1
	  if($match == $_GET['num']){
	    $val++;
	  }
	}
	
	// write this line
	$temp_string .= $name."=".$val."\r\n";
  }

  fwrite($fp, $temp_string);
  fclose($fp);  
}


Series this article:
Flash Database: Text File
Flash Database: PHP for Reading Data
Flash Database: Saving Data at Server Side
Flash Database: Switching Task at Server Side
Flash Database: Starting Flash
Flash Database: Making Flash Polling Interface
Flash Database: Giving Action to Submit Polling
Flash Database: Trying Submiting Vote
Flash Database: Preparing Polling Result Interface

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting