Browser MMO Video#2

Location of the Videos
Post Reply
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Browser MMO Video#2

Post by hallsofvallhalla »

second video, how to build the database and enter some data. Also building the connect.php. Post any Q and A and comments in this thread.

[vimeo]http://vimeo.com/4828407[/vimeo]

the video is in HD but vimeo only allows 1 HD a week, so it wont be for now, i will find an alternative or next week upload it in HD. I zoom in to all the coding so you dont need HD.


source

connect.php

Code: Select all

<?php

$db = mysql_connect("localhost","root","") or die("Could not connect to db");
if(!$db)
 die("no db");
if(!mysql_select_db("tutorial",$db))
 die("No Database Selected");
 
 ?>
test.php

Code: Select all

<?php
include 'connect.php';

$playerinfo ="select * from players where name = 'player1'";
$playerinfo2 = mysql_query($playerinfo) or die ("could not select players");
$playerinfo3 = mysql_fetch_array($playerinfo2);

echo "Player1's email is " . $playerinfo3['email'];
echo "<br>Player1's id is " . $playerinfo3['id'];

?>
Falken
Posts: 438
Joined: Fri May 08, 2009 8:03 pm

Re: Video#2

Post by Falken »

Good tutorials I must say even tho I know php quite well :P

Some details that is good to mention. In your code if there is 2 players called "player1" it will only return one of them or in some cases throw an error.
To fix this either loop the array and echo all players or add " LIMIT 0, 1" in the end of the sql string, that way it will only retrieve the first player1 row found in the database. You could also use mysql_fetch_row instead of array if you just want one row too
--- Game Database ---
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#2

Post by hallsofvallhalla »

thanks Falken. I have seen the results of your PHP coding so I value your opinion very much.

Thats why I always use auto increment id. I query it and there is no chance for pulling 2 of the same. ;) For demo purposes I used name. THough I do use limit one much when i am using a inventory system, help keep from deleting or moving 2 of the same item.
Falken
Posts: 438
Joined: Fri May 08, 2009 8:03 pm

Re: Video#2

Post by Falken »

Ye using ID is the best thing. Altho if all usernames has to be unique tho, there is no reason why you couldn't remove the id and set username as primary key instead.
--- Game Database ---
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#2

Post by hallsofvallhalla »

that is true, my main reason for it is so I always have a count of how many players there are without having to to do a for loop with a query and because I often separate skills, stats, inventory, ect to other tables and I link them by a id, then the skills and stats tables are non numerical character free and use less space and pull faster. Guess its just a habit.
User avatar
Raven67854
Posts: 893
Joined: Thu Apr 23, 2009 12:51 am

Re: Video#2

Post by Raven67854 »

Nice job on the tutorial halls.
C/C++/C#/Blitzmax/Visual Basic Programmer
Blender/XSI user
"It's not what you use. It's how you use it what you have" -Unknown author
"Sleeping the number one cause of death" -Raven67854
""No matter how much shit life throws at me. I will keep on going just to piss life off." -Raven67854

PC Specs:
AMD Athlon 64x2 5000+ 2.6ghz Black Edition
8 gigs Corsair ram 1066mhz
9800GTX+
2x750gb HD
Vista Home Premium X64
Ubuntu 9.04 X64
Falken
Posts: 438
Joined: Fri May 08, 2009 8:03 pm

Re: Video#2

Post by Falken »

ok!
hallsofvallhalla wrote:that is true, my main reason for it is so I always have a count of how many players there are without having to to do a for loop with a query.
A little hint for the future if you need something like that. (Like if the player with id 3 is removed, then the last id of lets say 23 wont be correct ;) )
You can easily use the following sql query to count rows:

Code: Select all

SELECT COUNT(*) AS myCount FROM myTable;
or in php:

Code: Select all

$sql = "SELECT * FROM myTable";
$count = mysql_num_rows($result);
that returns the number of rows that the query got. Very useful :)
--- Game Database ---
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
User avatar
kyraneth
Posts: 664
Joined: Thu Apr 23, 2009 2:56 pm

Re: Video#2

Post by kyraneth »

you two really know your codes don't you :D I still haven't got to check the vids, i'll probably do it in the afternoon.
Just FYI, the post is above, so stop looking down here and do something useful.

king noob. Nice.
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#2

Post by hallsofvallhalla »

check the vids!!!! heeh i am still waiting to for people to choose what this game is about. IF I don't get answers soon I will choose myself.
Socapex
Posts: 16
Joined: Sun Jun 14, 2009 10:00 pm

Re: Video#2

Post by Socapex »

Thank you very much for the vids, I'm liking it alot! I'm presently following on mac with MAMP and textmate, and after small tweaks it works fine. I'll be posting up anything that mac users might bump into. As for this video (and the first)...

When connecting to MAMP on your browser, use "localhost:8888" instead of just "localhost".

If you ever bump into the error (when running the script either in textmate or what-not) that resembles: Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)

You'll have to create a symbolic link to "/tmp/mysql/mysql.sock" in your var folder...
Launch your terminal,
> cd ..
> cd ..
> cd /var
> sudo mkdir mysql
>cd ..
> sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

There, everything works fine :)
Socapex
Post Reply

Return to “Older Browser MMO Videos”