sorry for the unclear title but I couldn't come up with anything better.
My dilemma is this:
I have one InnoDB table in my database called "meetings" with the following structure:
- meeting_id (primary key, auto_increment)
- user1_id (foreign key pointing to a user_id in a table called "users")
- user2_id (foreign key pointing to a user_id in a table called "users")
- time (type DATETIME)
- location (type VARCHAR(200))
The table "users" is basic and looks like this:
- user_id (primary key, auto_increment)
- first_name (type VARCHAR(30))
- last_name (type VARCHAR(30))
I have a PHP file with the aim to simply print out a description of the meeting, e.g.:
You saved the following meeting information:
User 1 | User 2 | Time & Date | Meeting location
John Doe | Jane Doe | 2010-10-10 10:10:10 | New York
Now, I simply want to use the meeting ID, call my database (only the "meetings" table) and be able to get the first_name and last_name of the user1 and user2.
Right now, my non-working code looks like this:
$query = "SELECT * FROM meetings WHERE meeting_id = 1";
$data = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($data); // ANY CHANGES HERE?
...
echo '<p>You saved the following meeting information::</p>';
echo '<table>';
echo '<tr><th>User 1</th><th>User 2</th><th>Time & Date</th><th>Meeting location</th></tr>';
echo '<td>' . $row['user1_id']['first_name'] . ' ' . $row['user1_id']['last_name'] . '</td>'; // NON-WORKING
echo '<td>' . $row['user2_id']['first_name'] . ' ' . $row['user2_id']['last_name'] . '</td>'; // NON-WORKING
echo '<td>' . $row['date_time'] . '</td>';
echo '<td>' . $row['location'] . '</td>';
echo '</table>';
...
(How) can I retrieve the first_name/last_name links without making separate calls to the "users" table? When I check phpMyAdmin, the InnoDB foreign key links seem to work fine. Many thanks in advance!