As a beginner I'm not fan of concatenating but I think this is something that would be really useful for me to know. So I have a while statement that gets data from a table in a database. I'm using a second query below and in between that while statement to display extra information from a different table.
<?php while($employeeproject=mysqli_fetch_array($resultemp)){ ?>
<td data-th="Employee">
<!-- INNER JOIN EMPLOYEE TO GET NAMES -->
<?php $sqlemps="SELECT first_name, last_name FROM employees INNER JOIN employeeprojects ON employees.employee_id=employeeprojects.employee_id";$resulempls=mysqli_query($db,$sqlemps);$displayempnames = $resulempls->fetch_assoc();?>
<?=$displayempnames['first_name'];?> <?=$displayempnames['last_name'];?>
</td>
<?php };?>
The while statement gets info from employeeprojects
and I display names joining with employees
table. It works but problem is the program displays the same name even if it's a different employee_id
. I'd like to concatenate and add a WHERE clause in the second query but im not sure how.
Something like...
$sqlemps="SELECT first_name, last_name FROM employees INNER JOIN employeeprojects ON employees.employee_id=employeeprojects.employee_id WHERE employee_id=<?=$employeeproject['employee_id'];?>";
Obviously this will not work so how do I concatenate?