Computer Science Canada

Linking Tables

Author:  Archi [ Wed Oct 29, 2003 4:49 pm ]
Post subject:  Linking Tables

I've finally got my game off the ground and need a little assistance with onme thing. I have a table for the users which sign-up and also a table for the users stats. Now, how would I go about linking these tables so that when a user signs-up, not only is the info placed into user table but a row gets placed into the stat table according to the username?

Eg..
User Signs-Up
Info goes to user table
Username goes to stat table and creates random stats.

Author:  Homer_simpson [ Wed Oct 29, 2003 5:57 pm ]
Post subject: 

Use < td> and < tr> :S

Author:  Archi [ Wed Oct 29, 2003 7:15 pm ]
Post subject: 

Huh???I'm referring to linking tables within a database.

Author:  PaddyLong [ Thu Oct 30, 2003 2:41 pm ]
Post subject: 

... just have another query to put the info into the stats table Confused

Author:  Archi [ Thu Oct 30, 2003 4:15 pm ]
Post subject: 

thats what i was trying...but for some reason its not working....I'm using a premade user authentication script type thing...SO I added my query to the end of it, but its not quite working...:S

And i had tried to post the file here...but it didn't work

Author:  Archi [ Sat Nov 01, 2003 11:42 am ]
Post subject: 

Well do any of you people use phpmyadmin? Because I found a way to link them using that..i just need help trying ot set it up

Author:  Homer_simpson [ Sat Nov 01, 2003 2:32 pm ]
Post subject: 

add an ID to the records in everytable.... so u enter the userinfo data to the info table with some id number for example 8... then u enter the username to the user table with same id 8... so now u can make query to the database and ask for the record with the id 8... so now u can have everyrecord with IDs and u can link them to eachother... btw the ID is and INT and has to be autoincrement.

Author:  Amailer [ Sat Nov 01, 2003 2:51 pm ]
Post subject: 

autoincrement.
I don't like that at all...it creates so much troble...
What i do is when i enter the id,
i just get the last id that is there in the table and $id++; it ;D
So, if i delete arecord, it works prefectly. ( and want to add a new one )

Author:  Homer_simpson [ Sat Nov 01, 2003 6:59 pm ]
Post subject: 

i haven't had trouble with it...

Author:  Archi [ Sun Nov 02, 2003 1:19 am ]
Post subject: 

yea..auto-increment can be a pain..especially when your testing a lot...and homer..i've tried that..the thing is...its not adding anything to the second table...

Author:  octopi [ Sun Nov 02, 2003 2:39 pm ]
Post subject: 

Maybe you could post some code..so we can see what your doing wrong....or not...you can just keep telling us its not working, and we can throw random ideas out.

Its up to you.

Author:  Archi [ Sun Nov 02, 2003 3:02 pm ]
Post subject: 

ok, i will attach the file as a *.txt file...THe code which doesn't work is between to //tags which describe the situation..Its part-way through the code.

Author:  Amailer [ Sun Nov 02, 2003 5:21 pm ]
Post subject: 

For me the code works, (ones that i create using auto-increment)
But sometimes it creates problems, but it still works....

Author:  Archi [ Mon Nov 03, 2003 9:48 pm ]
Post subject: 

Has anyone seen anythnig wrong with the code?

Author:  Amailer [ Mon Nov 03, 2003 10:21 pm ]
Post subject: 

Lets see, have you got your table names all correct?
uname, str, def, agi, abi, acc, hp, hpl, mp, mpl, gold

code:

// CODE THAT ISN"T WORKING AT ALL...IVE TRIED IT IN MANY SPOTS AND NOTHING.     
$str=intval(rand(3,6));
$def=intval(rand(1,4));
$agi=intval(rand(2,5));
$abi=intval(rand(1,3));
$acc=intval(rand(20,40));
$hp=intval(rand(25,40));
$mp=intval(rand(10,15));
$hp=$hp+40;
$mpl=$mp;
$hpl=$hp;
$gold=intval(rand($str+$def+$agi,$hp+$mp));

$result = mysql_query("INSERT INTO stats (uname, str, def, agi, abi, acc, hp, hpl, mp, mpl, gold)
                VALUES ('$username','$str', '$def','$agi','$abi','$acc','$hp','$hpl','$mp','$mpl','$gold')");
//END OF CODE THAT DOESN'T WORK


(THIS IS A QUESTION ;D not a correction)

Author:  Archi [ Mon Nov 03, 2003 10:48 pm ]
Post subject: 

Yes they are named correctly...COuld it have anything to do with my table actually having 2 more columns than wat i am telling it to insert? It also has a lim and exp column which is set to 0 as default.


: