#12001/3/17 16:27:29
///////////Programed by Demon.S a free code
///////////You can use it in your scoreboard-programe,there are 2 action "pushdata","getdata"
///////////that you must transform to here,and also vars like "name","score" must trans to ///////////here(when you wanna push data),result will be returned a pushed=ok or getedXX,max ///////////spefics a var that the max num you want display.
///////////需要传递的变量是pushdata或者是getdata,pushdata的时候也需要传递name,score,push返回值是
///////////pushed=ok,get的返回值是getedxx.
///////////thanx for useing my code.
//initiat
$server="your server";
$user="user";
$pass="password";
//prepare
$pushed=mysql_connect($server,$user,$pass);
if (!$pushed){
echo "database error.";
}
$pushed=mysql_select_db("score");
if (!$pushed){
echo "select error.";
}
//push
if ($action=="pushdata"){
$query="insert into userscore (name,date,score) values ('$name',now(),'$score')";
$pushed=mysql_query($query);
if (!$pushed){
echo "insert error.";
}else{
echo "&pushed=ok";
}
}
//get
if ($action=="getdata"){
$max=10;
$query="select * from userscore";
$geted=mysql_query($query);
$geted_num=mysql_fetch_row($geted);
$num=count($geted_num)
for ($i=0;$i<$num-1;$i++){
for ($j=$i+1;$j<$num;$j++){
if ($geted_num[$i]<$geted_num[$j]){
$temp=$geted_num[$i};
$geted_num[$i]=$geted_num[$j];
$geted_num[$j]=$temp;
}
}
}
//output
for {$i=0;$i<$max;$i++){
echo ("&geted".$i.$geted_num[$i]);
}
?>
环境,php+mysql