Nathan Nathan - 1 month ago 5x
HTML Question

tables and links messing the code up

I have a problem with PHP and links, I mean, I'm trying to use

<a href
to link the id of a ticket and then display it to user, but the problem is that the link I get is like


and it should only be like


This is the code:

if ($result = $con->query($query))
echo '
<table id="tfhover" class="tftable" border="1">
<th>ID Tiketa</th>
while ($row = $result->fetch_assoc())
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['Autor'] . "</td>";
echo "<td><a href=\"viewticket.php?ticketid=". $row['ID'] .">". $row['Naslov'] ."</a></td>";
echo "<td>" . $row['Kategorija'] . "</td>";
echo "<td>" . $row['Datum'] . "</td>";
echo "</tr>";


When you change your Markup everything should be fine:

    while ($row = $result->fetch_assoc())
    echo '<tr>';
    echo '<td>' . $row['ID'] . '</td>';
    echo '<td>' . $row['Autor'] . '</td>';
    echo '<td><a href="viewticket.php?ticketid='. $row['ID'] .'">'. $row['Naslov'] .'</a></td>';
    echo '<td>' . $row['Kategorija'] . '</td>';
    echo '<td>' . $row['Datum'] . '</td>';
    echo '</tr>';

The Reason for this is, that there is a big difference between Single Quotes and Double Quotes.

Single Quotes are not parsed by PHP, so

$variable = 'hello';
echo '$variable' 

will still return: $variable


echo "$variable"

will parse the string to: Hello

This way you would have seen, that you missed an escaped double quote.