SA-MP Forums Archive
How to 'link' the two ids? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to 'link' the two ids? (/showthread.php?tid=397178)



How to 'link' the two ids? - Elysian` - 03.12.2012

Okay, I've got vID save in the player table and a vID in the vehicles table on MySQL..

How would I 'link' these both for a player to know it's his car?


Re: How to 'link' the two ids? - Elysian` - 03.12.2012

And that is?


Re: How to 'link' the two ids? - Sinner - 04.12.2012

Use joins.

PHP код:
SELECT *
FROM usertable JOIN vehicletable
    ON usertable
.vID vehicletable.vID 
This will return all players that have a vehicle. If you want all players, even those who don't have a vehicle use LEFT JOIN.

PHP код:
SELECT *
FROM usertable LEFT JOIN vehicletable
    ON usertable
.vID vehicletable.vID 
Documentation: http://www.w3schools.com/sql/sql_join.asp


Re: How to 'link' the two ids? - Elysian` - 04.12.2012

Lolwut?

I honestly don't get what you just said.

EDIT: I get this error.
No database selected

And I've got this.

Код:
SELECT * 
FROM players JOIN vehicles
    ON players.vehicleID = vehicles.vID



Re: How to 'link' the two ids? - Bakr - 04.12.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
Foreign keys.
!!
http://dev.mysql.com/doc/refman/5.1/...nstraints.html


Re: How to 'link' the two ids? - Elysian` - 04.12.2012

Is this it?




Re: How to 'link' the two ids? - Elysian` - 04.12.2012

Yes, I read this one:
http://dev.mysql.com/doc/refman/5.1/...nstraints.html

But, is that what it is in the picture above?


Re: How to 'link' the two ids? - Elysian` - 04.12.2012

I didn't use the GUI. I went into Player > Structure > Relation View > Here.


Re: How to 'link' the two ids? - Bakr - 04.12.2012

That would be you using the GUI.

Regardless, find the section of the program you are using to navigate through your database that you can execute code from. Make changes to the table using the code from that documentation, as appropriate.


Re: How to 'link' the two ids? - Elysian` - 04.12.2012

I've tried doing it the other way and it doesn't work.