Jump to content

getting php code to do as i wish


chris_s_22

Recommended Posts

im trying to figure out when a form is filled out each set of players gets the same gameno although if another form was to be submitted the gameno would be unique

 

if theres a tutorial please send link thx

 

for example

form1

PLAYER - SEX - GAMENO

player1 - male - 1

player2 - female - 1

player3 - male - 1

player4 - female - 1

 

form2

PLAYER - SEX - GAMENO

player1 - male - 2

player2 - female - 2

player3 - male - 2

player4 - female - 2

 

heres the code im working on,

<?php
function create_game($playername0, $sex0, $playername1, $sex1, $playername2, $sex2, $playername3, $sex3, $playername4, $sex4, $playername5, $sex5, $playername6, $sex6, $playername7, $sex7, $playername8, $sex8, $playername9, $sex9, $playername10, $sex10, $playername11, $sex11, $playername12, $sex12, $playername13, $sex13, $playername14, $sex14, $finalscore) 
{
// store the information in the database
    $query = "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername0','$sex0','$finalscore')";
$result = mysql_query($query) or die(mysql_error());
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername1','$sex1','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername2','$sex2','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername3','$sex3','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername4','$sex4','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername5','$sex5','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername6','$sex6','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername7','$sex7','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername8','$sex8','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername9','$sex9','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername10','$sex10','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername11','$sex11','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername12','$sex12','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername13','$sex13','$finalscore')";
$result = mysql_query($query) or die(mysql_error());		 
$query =  "INSERT INTO `game` (`name`, `sex`, `finalscore`) values ('$playername14','$sex14','$finalscore')";
$result = mysql_query($query) or die(mysql_error());

// if suceesfully inserted data into database, send confirmation link to email 
if($result) 
{
    header('Location: [url=http://www.pinkangel4u.com/truthdare/Game/gameboard.php');]http://www.pinkangel4u.com/truthdare/Game/...oard.php');[/url]
    }
}
?>

Link to comment
Share on other sites

ok ill try explain things more clearly, im creating my own truth/dare game

this is my form that people will fill out if they want to play, Form can be viewed here.

 

when the form is submitted it adds all the data into my database, in the database i have the following feilds

id - which is autoincrement

gmaeno -

name - name of players entered in form

sex - sex of each player in form

score - default 0 ill need this has ill be refering to it later on in my game

 

 

so has you see from the script i posted in my initial post each player creates a entry into the table.

 

so what im trying to do it get all entries within the entered form to have the same gameno.

 

but then if another game was created with a different set of players the gameno would be different to the first group of players

 

if theres anything u dont understand or would like further info let me know

Link to comment
Share on other sites

Difficult to understand

 

Ar you trying to assign game no to all player randomly???

 

consider i came and filled my details so randomly i will be having a gameno and get entry in the game

one more person follow and enter details now this fellow should get some other gameno ???

 

Please explain in steps would be lot easier!! :-)

Link to comment
Share on other sites

i dont understand why people carnt undertand i think im expaining very simply

anyways please visit the site http://pinkangel4u.com/truthdare/Game/

 

as you can see if this is a form, so say someone was having a party at home and there was a group of people wanting to play the game they would all enter there names and there sex, this information would then be entered into the database

 

however say there was another party at some other location and they wanted to play this game, they would enter all the names and sex

 

i need to seperate the first game from the second game. to do this i created a feild called "gameno" in the table database,

 

i am asking how do i add the same value in the "gameno" feild for each form filled in

 

each form filled in will represent one game

 

 

Link to comment
Share on other sites

Considering you don't have particular table for {gameid - game  name} it is generic.

 

you can do is when ever your form is loaded you can assign a random unqiue id

 

<input type="hidden" value="$gameno" id="gameno"/>

 

where $gameno='G_'.mt_rand(0,99).'xx';

 

in database when you will insert - you will receive in your POSt is name,sex and gameno and this gameno will be same for these players where as it will be different for every person who is filling the form.

 

Hope i make some sense !!

 

Regards

 

Link to comment
Share on other sites

I saw your site! It looked quite fun! ;D And I don't even like truth or dare haha.

 

Anyway when I had a similar problem, I created two tables. In this case, one for the game information, one for the players.

 

There's probably better ways to do it, but I did it like so:

$s = mysql_query("SELECT GameID FROM `GameInfoTable`") or die(mysql_error());
while ($fetch = mysql_fetch_assoc($s)) {
$count = mysql_num_rows($s);
$sID = 1;
$sID = $count+$sID;
}
$GameID = $sID;

 

Then insert into the players table using the $GameID. Every new game will have a unique ID then and if you'd like you can more easily store other information about specific games that are the same for every player (such as the Final Score or date the game was played).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.