Home Community Mys-Script Creative Off-Topic |
|
|
Thread Tools | Display Modes |
#1
|
||||
|
||||
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:
--- Work in progress --- |
#2
|
||||
|
||||
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. |
#4
|
||||
|
||||
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 |
#5
|
||||
|
||||
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. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Gradient Map Tutorial | Whimsy | Art Gallery | 0 | 10-20-2014 04:55 PM |
OOP Tutorial request | Ruinily | Suggestions and Feature Requests | 4 | 02-09-2013 01:42 PM |
Basic PHP & MySQL Tutorial | Kaeliah | Tutorials and Tips | 8 | 03-23-2011 07:50 PM |
PHP/MySQL Tutorial | HIddenPanda | Tutorials and Tips | 0 | 01-27-2011 05:30 PM |
Quick php tutorial | Ajof | Tutorials and Tips | 18 | 11-08-2010 12:20 PM |
What's New? |
What's Hot? |
What's Popular? |