Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Tutorials and Tips

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 01-30-2011, 03:39 PM
Kaeliah's Avatar
Kaeliah Kaeliah is offline
Premium Member
 
Join Date: Sep 2010
Location: Pennsylvania, United States
Posts: 485
Gender: Female
Credits: 32,337
Kaeliah will become famous soon enough
Send a message via AIM to Kaeliah Send a message via MSN to Kaeliah
Default Intermediate PHP & MySQL Tutorial I

PHP & MySQL have a ton of useful functions you can use in order to do what you want. In this tutorial, we'll look at creating simple games, and the functions you would need to create the game from scratch. Sounds a bit overwhelming, but don't worry, we'll go through it step by step. If you get lost or are confused about something, feel free to ask questions of me, or other coders on the forum. We don't bite, we nibble. Anyway, on to the game project!!


1. Planning & Outlining

If you've ever written an essay or done a craft you should know a little bit about planning and outlining. As a newer coder, it's crucial that you learn how to do this at least a little bit so you have an idea in your head before you get to the notepad. First start off with the challenge. What is it you want to do? In this case we're programming a card game. So let's outline the rules of the card game and how it should work when it's fully programmed.

Five cards are shown, each with the option of keeping or throwing out. The goal of the game is to get as high a poker hand as you can, and the better the hand the bigger the reward you receive.

Now how do you program something like this? This isn't a question I expect you to know the answer to just yet, as there are many aspects to programming this game that have not yet been covered by my tutorials, but try to think in programming terms. A good place to start is database needs. In this case, we should probably have a way to store each card and information about the card. You could also choose to store information about the rewards, but in this case we'll use a simple enough reward system you won't need to. Next think about what the program should look like and what functions it should have. Do you want guests to be able to play the game? Are there any possible ways of cheating? What should the game look like when it's done? Think about these kinds of things and write a simple outline for yourself like this:

Game Ideas
- Members only!
- Use forms so members can't cheat.
- Cards laid out with the options below each.

Once you think you've got everything covered move on to the next stage. Although don't worry, you can always add or take away from these lists, it's just a way to keep your brain organized.


2. Creating Tables

In MySQL you can get, update, create or delete information, which is what makes MySQL such a popular tool in PHP. Now it isn't required, but to make the program smaller and more dynamic we're going to store all the card information in a table. But before we get into creating a table, we need to go over some vocabulary.

Table - Think HTML table. That's what it looks like. It stores information, and also information ABOUT the stored information.
Field - An equivalent in HTML would be a column of a table. A field is simply one column of the table that stores one type of information.
Null - Null basically means empty. Setting a field type to 'Null' allows it to be empty.
Primary Key - A primary key makes each row in the table unique. Most often it's used as an 'ID' field.
int - Is short for 'integer' and indicates the field holds number values only.
varchar - Holds any characters.
Auto_Increment - Automatically sets a value and increments it every time a new row is made.

Don't worry, you'll get to see each of these vocab words in action. Now on to creating the table! Start a new file and call it 'install.php'. Do not run this file until the tutorial tells you to! Now write in the start and ending for a php file(Refresher: '<?php' and '?>') and then we'll start the MySQL statement to create the table as follows...

PHP Code:
/* This is not part of creating the MySQL table, you need this to connect TO the database first! 
Make sure you have a copy of the Mysidia Adoptables already installed, 
or you can set the variables to a separate database if you'd like */
include("inc/config.php"); 
$conn mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to MySQL');
mysql_select_db($dbname);
// End connecting

// Start Creating
mysql_query("CREATE TABLE cards 
(
CardID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(CardID),
CardValue int(11),
CardSymbol varchar(120),
)
"
); 
Now if you're confused, don't be worried. 'CREATE TABLE cards' is telling the database to create a new table, and call it cards. Then within the inner set of '( )' we're listing fields. The first field is CardID, it's information will be numbers or 'int', it cannot be empty or NULL, and it will automatically increment with each row. Because the AUTO_INCREMENT will make 1 value in each row completely unique, we'll make it the primary key as seen in the next line. Then after that we create a second field called 'CardValue' which will be a number(Jack = 11, Queen = 12, King = 13, Ace = 1). 11 is the standard integer length, meaning it allows a sequence total of 11 numbers. The third and final field is the CardSymbol, wheter it's hearts, diamond, spades or clubs.


--- Work in progress ---
__________________
[My Shop] ♥ [My Blog] ♥ [Subscribe] ♥ [My Mods] ♥ [Mod TOS]
Reply With Quote
  #2  
Old 01-30-2011, 10:41 PM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 333,966
Hall of Famer is on a distinguished road
Default

This looks like a very interesting Kaeliah, it will help a lot for programmers with a certain degree of PHP skills.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
  #3  
Old 01-31-2011, 10:57 AM
Kaeliah's Avatar
Kaeliah Kaeliah is offline
Premium Member
 
Join Date: Sep 2010
Location: Pennsylvania, United States
Posts: 485
Gender: Female
Credits: 32,337
Kaeliah will become famous soon enough
Send a message via AIM to Kaeliah Send a message via MSN to Kaeliah
Default

It's a work in progress right now. ^.^ More to come very soon.
__________________
[My Shop] ♥ [My Blog] ♥ [Subscribe] ♥ [My Mods] ♥ [Mod TOS]
Reply With Quote
  #4  
Old 01-31-2011, 02:01 PM
PTGigi's Avatar
PTGigi PTGigi is offline
Crazily Friendly~HoF
 
Join Date: Jul 2009
Location: Somewhere >.>
Posts: 370
Gender: Female
Credits: 26,307
PTGigi
Default

Looks nice so far

LOL I fail at the first step XD I never do that Well only because I usually do that step in my mind for about a week or more and get the idea stuck there XD
__________________


"I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo
My Adoptables|Nuzlocke Webcomic
Reply With Quote
  #5  
Old 01-31-2011, 03:20 PM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 333,966
Hall of Famer is on a distinguished road
Default

Well I was wondering if there's a way to store a double type variable in mysql, looks like the only way to do that atm is to store it as string, and then convert to double when calling from PHP.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Gradient Map Tutorial Whimsy Art Gallery 0 10-20-2014 03:55 PM
OOP Tutorial request Ruinily Suggestions and Feature Requests 4 02-09-2013 12:42 PM
Basic PHP & MySQL Tutorial Kaeliah Tutorials and Tips 8 03-23-2011 06:50 PM
PHP/MySQL Tutorial HIddenPanda Tutorials and Tips 0 01-27-2011 04:30 PM
Quick php tutorial Ajof Tutorials and Tips 18 11-08-2010 11:20 AM


All times are GMT -5. The time now is 10:51 AM.

Currently Active Users: 9716 (0 members and 9716 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636