1

I have two tables with the same id. How I can take two tables from the same string. I have tried this but doesn't work. I need it to use the data from both tables on the same page I have tried also this $sql = "SELECT vm_users.*, vm_menu.* FROM vm_users , vm_menu WHERE id = ? ";

$id = $decoded["id"];
$id_user_type = $decoded["id_user_type"];
$sql = "SELECT * FROM vm_users, vm_menu WHERE id = ? ";           
$mysqli->set_charset("utf8");     
$statement = $mysqli->prepare($sql);
$statement->bind_param('i', $id );
$statement->execute();
$result = $statement->get_result();
$user = $result->fetch_array(MYSQLI_ASSOC);

now I have this error

Fatal error: Uncaught Error: Call to a member function bind_param() on bool in /web/htdocs/home/view/top_pannello_personale.php:18 Stack trace: #0 /web/htdocs/home/gestione_menu.php(1): require() #1 {main} thrown in /web/home/view/top_pannello_personale.php on line 18

Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

2

You should use a join e.g.:

SELECT vm_users.* , vm_menu.*
FROM vm_users
INNER JOIN  vm_menu WHERE vm_users.id = vm_menu.id 
AND vm_menu.id = ?

Based on your schema you should adapt the proper join condition vm_users.idmenu = vm_menu.id

Dharman
  • 30,962
  • 25
  • 85
  • 135
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107