Question: Chess game form for entering moves?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zwiggybo
Forum Newbie
Posts: 3
Joined: Sun Jul 16, 2006 4:04 pm

Question: Chess game form for entering moves?

Post by zwiggybo »

I am a novice at programming with php, and yesterday decided I would try a new 'little' project. At first I thought it would be easy, but now I am looking at things a bit differently.

Really, what I am trying to do is create a form that will be able to generate all the fields I would need to enter for every move in a given chess game into a mysql database. I emphasize the all because rather than enter each pair of moves, then hit 'enter' and return to the form to enter the next row I am thinking that if I know how many pairs of moves (i.e black, white) there are, then there must be a way to generate a form with xx many fields, then enter the moves, then hit enter once.

Any hints on accomplishing this would be great! Or maybe it has been done before?


Thank you
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Chess.... forgotten all about that game. My dad used to play constantly in competitions and stuff to the point that he actually had to get physio help for his bad back from leaning over a chess table all the time :P Nice set of trophies though :)

*cough* OK, I wasn't clear if you are saying that you *do* know how many moves were made or if you need to calculate that? I can't see how you could do the latter unless you played the game back on the computer. The former is very easy however if you need to generate a list of fields XX times.

PS: Welcome to Devnet ;)
zwiggybo
Forum Newbie
Posts: 3
Joined: Sun Jul 16, 2006 4:04 pm

Post by zwiggybo »

Thanks for the welcome d11wtq :)

Actually, all the moves would be known because what I am really looking at doing is entering/ having people enter famous games, or interesting games.

I suppose if I can accomplish this, then my next experiment would be to run querys on the games based on opening moves (just an idea).

So, generating a list of fields a known number of times is really what i need to do. I would say making a form using XMLHTTPRequest, but for now I want to keep it as simple as possible so I actually understand the logic of what I am doing.

-- Any examples, ideas, or places to look?


Thanks again
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

It's a simple 'for' loop.

Code: Select all

<ol>
<?php

$number_of_moves = 92; //For example

for ($i = 1; $i <= $number_of_moves; $i++)
{
    echo "<li>W <input type=\"text\" name=\"white_from[$i]\" /> <input type=\"text\" name=\"white_to[$i]\" />,
    B <input type=\"text\" name=\"black_from[$i]\" /> <input type=\"text\" name=\"black_to[$i]\" /></li>\n";
}

?>
</ol>
Now when the form is submitted you can get an array for $_POST['white_from'], $_POST['white_to'] and the same for black. If you print_r() those you should get an idea what to do next but let's get as far as generating the list first ;)
Post Reply