mrlayance mrlayance - 1 year ago 61
PHP Question

php echo and backslashes

For life of me I can not get this working...

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<a href=\"concert.php?id=. $row["id"] .\">. $row["date"] .</a>"
"<br>";
}


This is the error...


syntax error, unexpected '"', expecting identifier (T_STRING) or
variable (T_VARIABLE) or number (T_NUM_STRING)


I believe you just add escapes to html "?

Answer Source

You're missing some closing and opening quotes. Replacing some of those double quotes with single quotes will remove the need for those backslashes as well.

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo '<a href="concert.php?id=' . $row["id"] . '">' . $row["date"] . '</a><br>';
    }