0

I want to ask, how do I make data appear on my friend's column page?

    $frnd = $conn->query("SELECT * FROM `friend` WHERE id = '".$_SESSION['uid']."' LIMIT 7");

    while($friend = mysqli_fetch_assoc($sql)){
        echo "'.$idu.'";
        echo "'.$name.'";
    }

I can't find, maybe a friend here can help me?

Vidal
  • 2,605
  • 2
  • 16
  • 32
wiihii
  • 41
  • 8
  • You want to join two tables that are in different Databases? Why they are separated? You need to query first DB, gather ID's and later use these ID's in second database connection in `WHERE id IN ("[...]")`. – Justinas Feb 22 '19 at 08:21
  • Possible duplicate of [Switch between multiple database in PDO](https://stackoverflow.com/questions/9588775/switch-between-multiple-database-in-pdo) – Justinas Feb 22 '19 at 08:23

1 Answers1

0

My friend you can query 2 different databases on the same query if:

  1. The user/pass is the same for the 2 databases
  2. The 2 databases are on the same server.

Here is an example of the query.

$query ="
SELECT
    *
FROM
    database1.databaseUser,
    database2.databaseFriend
WHERE
    database1.databaseUser.uid = database2.databaseFriend.idu
    AND database2.databaseFriend.id = '". $_SESSION['uid'] ."'
LIMIT 7
";

You have to include the databasename.table to be able to perform the query.

hope it helps.

This is your full code updated, please make the adjustment for the databases etc.

$query ="

SELECT
    *
FROM
    database1.databaseUser,
    database2.databaseFriend
WHERE
    database1.databaseUser.uid = database2.databaseFriend.idu
    AND database2.databaseFriend.id = '". $_SESSION['uid'] ."'
LIMIT 7
";

 $frnd = $conn->query($query);

    while($friend = mysqli_fetch_assoc($sql)){
        echo "'.$idu.'";
        echo "'.$name.'";
    }

Vidal
  • 2,605
  • 2
  • 16
  • 32
  • yea next time i want ask again @Vidal, if my brain errors or blank. hahahaha – wiihii Mar 12 '19 at 19:14
  • no problem glad I helped, can you mark it as answered to let other user know that it helped you with your question. – Vidal Mar 12 '19 at 19:14