Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

php while loop – html a href inside loop of data

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"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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']
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading