Use JOINs with a single query to get the information you want instead of running multiple queries
If you are only retrieving a single record, don't use a while loop - a single fetch will suffice
Use prepared statements - don't put variables directly into the SQL string
<?php
/*
MK_users MK_role_access MK_baccounts
+-----+---------------+ +----------+----------+ +-----+------------------------+
| uid | fullname | | role_uid | role_bid | | bid | businessname |
+-----+---------------+ +----------+----------+ +-----+------------------------+
| 1 | Laura Norder | | 1 | 10 | | 10 | Amazon |
| 2 | Peter Dowt | | 2 | 20 | | 20 | Apple |
| 3 | Tom Di Canari | | 3 | 30 | | 30 | Paula's Poodle Parlour |
+-----+---------------+ +----------+----------+ +-----+------------------------+
*/
$_SESSION['id'] = 2; // provide a value
$res = $conn->prepare("SELECT ba.bid
, ba.businessname
FROM MK_role_access ra
JOIN
MK_baccounts ba ON ra.role_bid = ba.bid
WHERE ra.role_uid = ?
");
$res->bind_param('i', $_SESSION['id']);
$res->execute();
$res->bind_result($bid, $business);
$res->fetch();
echo "$bid - $business <br>"; //==> 20 - Apple
?>