I have two tables, which I'll call foo and bar. Each table has a primary key, foo_id and bar_id, respectively. Each row in foo can be part of a group, which is a row in bar - think members on a committee, each member can be on multiple committees and each committee can have multiple members. I have a joining table which can be called foo_bar, which has only two columns (one each for the primary key of the other two tables) and lists which foo is part of which bar:
| foo_id | bar_id |
| ------ | ------ |
| test | res |
| test | res2 |
| --------------- |
Here is my PHP (due to my webhost I am unable to use $stmt->get_result()):
$stmt = $db->prepare("SELECT bar_id FROM foo_bar WHERE foo_id = ?");
$stmt->bind_param("s", "test");
$stmt->execute();
$stmt->bind_result($result);
$stmt->fetch();
$stmt->close();
Right now, printing $result gives me "res". How do I make it so that my result is all of the bars that the test foo is part of?
SQL Fiddle: http://sqlfiddle.com/#!9/2dfd2/1
you can use
mysqlisomething like this :the
$resultswill have all the bar ids with foo id equal to "test".