phpeveryday.com

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


Flash Database: Switching Task at Server Side

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


Flash Database Step By Step Tutorial - Part 4: After create read and saving data, we make a switching. The switching is controlled by GET parameter, action.

The code like this:


switch($_GET['action']){
  case 'saveData':
    saveData();
	break;
  default:
    readData();
	break;
}

Below, complete code for polling.php:


<?
$file_data = "polling.txt";
$cookie_duration = 360;
$cookie_title = 'text_poll_1';

// prepare no cache
header("Expires: Mon, 01 Jan 1990 00:00:00 GMT");
header("Last-Modified: ". gmdate("D, d M Y h:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0; pre-check=0", false);
header("Pragma: no-cache");

function readData(){
  global $file_data;
  
  $fp = file($file_data);
  
  while(list($line, $value) = each($fp)){
    print "&" . eregi_replace("\r\n","",$value);
  }
    
}

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);  
}
switch($_GET['action']){
  case 'saveData':
    saveData();
	break;
  default:
    readData();
	break;
}
?>


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
SMS : Sending SMS with PHP and ActiveXperts (Part 1)

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


624
posting