
-----------------------------------
Archi
Wed Oct 29, 2003 4:49 pm

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.

-----------------------------------
Homer_simpson
Wed Oct 29, 2003 5:57 pm


-----------------------------------
Use < td> and < tr> :S

-----------------------------------
Archi
Wed Oct 29, 2003 7:15 pm


-----------------------------------
Huh???I'm referring to linking tables within a database.

-----------------------------------
PaddyLong
Thu Oct 30, 2003 2:41 pm


-----------------------------------
... just have another query to put the info into the stats table  :?

-----------------------------------
Archi
Thu Oct 30, 2003 4:15 pm


-----------------------------------
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
Sat Nov 01, 2003 11:42 am


-----------------------------------
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
Sat Nov 01, 2003 2:32 pm


-----------------------------------
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
Sat Nov 01, 2003 2:51 pm


-----------------------------------
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 )

-----------------------------------
Homer_simpson
Sat Nov 01, 2003 6:59 pm


-----------------------------------
i haven't had trouble with it...

-----------------------------------
Archi
Sun Nov 02, 2003 1:19 am


-----------------------------------
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
Sun Nov 02, 2003 2:39 pm


-----------------------------------
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
Sun Nov 02, 2003 3:02 pm


-----------------------------------
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.

-----------------------------------
Amailer
Sun Nov 02, 2003 5:21 pm


-----------------------------------
For me the code works, (ones that i create using auto-increment)
But sometimes it creates problems, but it still works....

-----------------------------------
Archi
Mon Nov 03, 2003 9:48 pm


-----------------------------------
Has anyone seen anythnig wrong with the code?

-----------------------------------
Amailer
Mon Nov 03, 2003 10:21 pm


-----------------------------------
Lets see, have you got your table names all correct?
uname, str, def, agi, abi, acc, hp, hpl, mp, mpl, gold


// 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)

-----------------------------------
Archi
Mon Nov 03, 2003 10:48 pm


-----------------------------------
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.
