I’m trying to get my while loop to function when fetching data that is equal to input field.
The Data set is functional, but I want to add a read, update and delete function to each field of data through an with allocated ID.
<tbody>";
while($row=$result->fetch_assoc()){
$output .="
<tr>
<td>".$row['id']."</td>
<td>".$row['fornavn']."</td>
<td>".$row['efternavn']."</td>
<td>".$row['mail']."</td>
<td>".$row['kursistnummer']."</td>
<td>".$row['unilogin']."</td>
<td><a href="read.php?id='. $row['id'] .'" class="mr-3" title="View Record" data-toggle="tooltip"><span class="fa fa-eye"></span></a></td>
</tr>";
}
$output .="</tbody>";
echo $output;
It outputs the following error
"Parse error: syntax error, unexpected identifier "read" in
C:\xampp\htdocs\helloworld\action.php on line 38"
so im guessing its a syntax error in my href
>Solution :
You must escape double quotes in your string:
<?php
$output .="<tr>
<td>".$row['id']."</td>
<td>".$row['fornavn']."</td>
<td>".$row['efternavn']."</td>
<td>".$row['mail']."</td>
<td>".$row['kursistnummer']."</td>
<td>".$row['unilogin']."</td>
<td><a href=\"read.php?id=". $row['id'] ." class=\"mr-3\" title=\"View Record\" data-toggle=\"tooltip\"><span class=\"fa fa-eye\"></span></a></td>
</tr>";
Or better to use sprintf function in next way:
$output .= sprintf(
'<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>
<a href="read.php?id=%s class="mr-3" title="View Record" data-toggle="tooltip">
<span class="fa fa-eye"></span>
</a>
</td>
</tr>',
$row['id'], $row['fornavn'], $row['efternavn'], $row['mail'], $row['kursistnummer'], $row['unilogin'], $row['id']
);