·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]ajax与php交互代码实例源代码参考(3)

时间:2013-03-06 08:47cnblogs.com
服务端执行页面 show.php ? php include_once'DB.class.php'; $ tg = new DB('localhost','root','wangxiang','fenghua','UTF8'); if($_GET[tag]=='show') { $ sql = SELECTId,titlefromnewslimit0, .$_GET[id]; my

服务端执行页面 show.php

  1. <?php 
  2. include_once 'DB.class.php'; 
  3. $tg = new DB('localhost', 'root', 'wangxiang', 'fenghua', 'UTF8'); 
  4.  
  5. if($_GET[tag]=='show') 
  6. { 
  7.     $sql = "SELECT Id, title from news limit 0," . $_GET[id]; 
  8.     mysql_query("set names 'utf8'"); 
  9.     $item = $tg->getAll($sql); 
  10.      
  11.     sleep(1); //暂停1秒 
  12.      
  13.     for($i=0; $i<count($item); $i++) 
  14.     { 
  15.         echo "<a href=news.php?nid={$item[$i]['Id']}>{$item[$i]['title']}</a><br>"; 
  16.     } 
  17. } 
  18. else if($_GET[tag]=='add') 
  19. { 
  20.     sleep(2);//暂停2秒 
  21.     if($_POST[user_name] != '' && $_POST[user_age] != '' && $_POST[user_sex] != '') 
  22.     { 
  23.         $sql = "insert into news (title, pic_path, content) values ('".$_POST[user_name]."', '".$_POST[user_age]."', '".$_POST[user_sex]."')"; 
  24.         mysql_query("set names 'utf8'"); 
  25.         $insert_id = $tg->insert($sql); 
  26.          
  27.         if($insert_id > 0) 
  28.         { 
  29.             echo "插入成功!"; 
  30.         } 
  31.     } 
  32.     else 
  33.     { 
  34.         echo "资料填写不全"; 
  35.     } 
  36. } 
  37. ?> 

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器