I have 1 mysql database named A with one table named USERS that holds a users ID, & NAME, & EMAIL.
On the site I am working on I have it set up so that when the user registers it automatically sets up a new seperate mysql database for each user which is named after their ID from the USERS table. So there are an unknown number of databases depending on how many people register but the names of the databases are easy 1D, 2D, 3D, 4D, 5D & so on. On each database I have 2 tables which are also named after the ID number from the USERS table FRIENDS & CARS. So 1FRIENDS, 2FRIENDS, 3FRIENDS, 4FRIENDS & 1CARS, 2CARS, 3CARS, 4CARS & so on. The FRIENDS table allows each user to make a list of other users on the site. The CARS field holds information on the toy cars each user collects. I am trying to write the PHP code to take A users FRIENDS & show all of their friends cars using UNION to connect all of the users friends CARS tables & order them by the date that each user added the info on each car but I can't figure out how to do it.
I can get it to work if I know exactly what friends a user has for example if a person is friends with user 1 & user 3 & I code it like this it will work.
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die
('Could not connect to MySQL: ' . mysqli_connect_error() );
$query = "SELECT * FROM 1D.1CARS UNION SELECT * FROM
3D.3CARS ORDER BY date_entered DESC";
if ($result1 = @mysqli_query($dbc, $query)) {
while ($row = mysqli_fetch_array($result1 )) {
But I won't know which people a user will choose to be friends with ahead of time nor do I want to type all of that out each time so I need to use some sort of variable & a loop or something to take the list each persons is friends with & do the UNION. Any help would be greatly appreciated.