Posted: 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.
Sponsor Sponsor
Homer_simpson
Posted: Wed Oct 29, 2003 5:57 pm Post subject: (No subject)
Use < td> and < tr> :S
Archi
Posted: Wed Oct 29, 2003 7:15 pm Post subject: (No subject)
Huh???I'm referring to linking tables within a database.
PaddyLong
Posted: Thu Oct 30, 2003 2:41 pm Post subject: (No subject)
... just have another query to put the info into the stats table
Archi
Posted: Thu Oct 30, 2003 4:15 pm Post subject: (No 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
Archi
Posted: Sat Nov 01, 2003 11:42 am Post subject: (No 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
Homer_simpson
Posted: Sat Nov 01, 2003 2:32 pm Post subject: (No 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.
Amailer
Posted: Sat Nov 01, 2003 2:51 pm Post subject: (No 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 )
Sponsor Sponsor
Homer_simpson
Posted: Sat Nov 01, 2003 6:59 pm Post subject: (No subject)
i haven't had trouble with it...
Archi
Posted: Sun Nov 02, 2003 1:19 am Post subject: (No 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...
octopi
Posted: Sun Nov 02, 2003 2:39 pm Post subject: (No 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.
Archi
Posted: Sun Nov 02, 2003 3:02 pm Post subject: (No 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.
Posted: Sun Nov 02, 2003 5:21 pm Post subject: (No subject)
For me the code works, (ones that i create using auto-increment)
But sometimes it creates problems, but it still works....
Archi
Posted: Mon Nov 03, 2003 9:48 pm Post subject: (No subject)
Has anyone seen anythnig wrong with the code?
Amailer
Posted: Mon Nov 03, 2003 10:21 pm Post subject: (No 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