cocos2d-x curl+PHP network programming ranking list (1) cocos2d x download Yu Guoli quick cocos2d x

WBOY
Release: 2016-07-29 08:49:20
Original
1340 people have browsed it

In order to try network programming, I read a lot of blogs by great people, so I will record this now so as not to forget it.

Before writing the connection code, we must do a few things first:

1. Build WAMP

2. Create a database

3. Write the PHP code

4. Test

1. Installation of wamp

This is relatively simple. I found an installation package from the Internet and installed it.

2. Create a database

I went online and downloaded Navicat for MySQL, which can visually operate the database and facilitate future operations. (1) Just fill in the IP, user name, and password above; (2) Create a new database user in the connection; (3) Create a new table in the newly created database, and then click Design Table to create what you need Data name and its data type; after completing the above steps of database preparation, the following is the preparation of PHP.

3. Write the PHP file: rank.php

This code is for my flappybrid to make rankings. The code is as follows:

<?php 
   header("content-Type: text/html; charset=utf-8");
   $link =@mysql_connect("localhost","root","");
   if(!$link)
     {
     die(&#39;Could not connect: &#39; . mysql_error());
     }
     mysql_query("set names utf8",$link); 
     mysql_select_db("user",$link); //连接数据库
$name_=$_GET["name"];//用GET的方法获取数据
$score_=$_GET["score"];
$sql="select* from user where name=&#39;$name_&#39;";
$result=mysql_query($sql);//查找有没有同名的
$row=mysql_fetch_array($result);
if($row)
{	
$score_max =$row[&#39;score&#39;];
if($score_>$score_max)	//如果有同名就跟之前的数据比较,如果比之前大就更新数据
	{
		$sql="update user set score='$score_' where name='$name_'";
		mysql_query($sql);
	}
	}
else
{//同名就插入新数据
$sql="insert into user(name,score) values('$name_','$score_')";
mysql_query($sql);
<span style="white-space:pre">	</span>}


$li="select* from user where 1 = 1 order by score desc";
$result=mysql_query($li,$link);
 for($count=1;($row=mysql_fetch_array($result))
 &&($count<mysql_num_rows($result)+1)&&($count<11);$count++)
&#160;{//选出前十并输出
&#160; $li= $row[&#39;name&#39;];
&#160; echo $row[&#39;name&#39;]."->";
  echo $row['score'];
 if($count<mysql_num_rows($result))
&#160;{echo ",";}

&#160;
&#160; }


?> 
Copy after login
4. Enter the URL http://127.0.0.1/ in the browser rank.php?name=bak&score=7758

The page displays bak->7758, and you can add different data several times.

The above introduces the cocos2d-x curl+PHP network programming ranking list (1), including the content of Cocos2d-X. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!