Daniel Daniel - 11 months ago 40
PHP Question

PHP conactenation with html

I'm trying to concatenate some

with my fetched value form my DB. But I got lost in '' . "" \

I'm sure I'm missing something small but I just can't see it.

while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo."<td>" . $row["interest"] . "</td>"
."<td>"."<a href=\"http://localhost/page/files/".$row["filename"]\"/>" . $row["filename"] . " </a></td>"
."<td>" . $row["reg_date"] . "</td>";

Answer Source

I suggest you use single quotes instead of double quotes for your html values as this can confuse things.

You also had a lot of mistakes. I wont go into detail but compare your code to this and you should see them.

I fixed the code for you.

while ($row = $result->fetch_assoc()) {
                    $returnedHTMl = "<tr>";
                    $returnedHTMl .= "<td>" . $row["interest"] . "</td>"
                    $returnedHTMl .= "<td><a href='http://localhost/page/files/".$row["filename"]."'>" . $row["filename"] . " </a></td>"
                    $returnedHTMl .= "<td>" . $row["reg_date"] . "</td>"; 

                    echo $returnedHTML

@tpojka is also correct you should assign variables but I kept it similar to your code as I am not aware as to your reasons for doing it this way.