I'm looking to join two SQL queries together if possible.. or an alternative method to achieve what I am wanting my table to show.
$sql = "SELECT id, title, description, multiple, staffid FROM projects";
$sql2 = "SELECT staff.firstname, staff.surname
FROM staff
JOIN projects ON staff.staffid = projects.staffid";
Currently, I am only able to show the results from one of the queries into my table however.. I would like title, description, multiple to show in the table PLUS the firstname of the staff that I am trying to retrieve using a join.
here is my code..
<?php include ('../resources/styling.html'); ?>
<?php include ('adminNavbar.php'); ?>
<div class="container content-area">
<div class="row">
<div class="col-md-12">
<div class="panel">
<br>
<div class="text-center border border-light p-5">
<p class="h4 mb-4">View Projects</p>
</div>
<br>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Project Title</th>
<th scope="col">Description</th>
<th scope="col">Multiple Attempts?</th>
<th>View</th>
<th>Created by</th>
</tr>
</thead>
<tbody>
</div>
</div>
</div>
</div>
<?php
include ('../resources/config.php');
$sql = "SELECT id, title, description, multiple, staffid FROM projects";
$sql2 = "SELECT staff.firstname, staff.surname FROM staff JOIN projects ON staff.staffid = projects.staffid";
$result = $db->query($sql);
$result2 = $db->query($sql2);
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['title']."</td>";
echo "<td>".substr($row['description'],0, 50)."....</td>";
echo "<td>".$row['multiple']."</td>";
echo "<td><a href='ProjectDetail.php?id=".$row['id']."'>View Project</td>";
echo "<td>".$row['firstname']."</td>";
}
$db->close();
?>
</tbody>
</table>
currently I am recieving the error
Notice: Undefined index: firstname in C:\xampp\htdocs\test\adminDashboard\ViewProjectsML.php on line 61
which I am aware is because I am not using result2. But with numerous trial and errors I can only get the table to show TITLE DESCRIPTION and MULTIPLE OR FIRSTNAME.. not both. I would be really grateful if someone could point me in the right direction.