Domanda

im having trouble using an image search within php tags, is it possible? My code bellow:

<?php
 echo "<div id=reviewname>Name: ".$dname['name']."</div>";
 echo "<div id=reviewseat>Seat: ".$dseat['seat']."</div>";
 echo "<div id=srating>Sound: ".$dsrating['s_rating']."</div>";
 echo "<div id=crating>Comfort: ".$dcrating['c_rating']."</div>";
 echo "<div id=vrating>View: ".$dvrating['v_rating']."</div><br /><br/>";
 echo "<div id=reviewcomment> Comments: ".$dcomment['comment']."</div>";
?>

I would like within these div's to be an image src example being:

echo "<div id=srating><img src="images/soundimg.png" alt="Sound" height="35" width="35"></div>Sound: ".$dsrating['s_rating']."</div>";

The above does not work, is it a syntactical issue?

Thanks

È stato utile?

Soluzione

You need to escape the quotes inside the echo statement

echo "<div id=srating><img src=\"images/soundimg.png\" alt=\"Sound\" height=\"35\" width=\"35\"></div>Sound: ".$dsrating['s_rating']."</div>";

Altri suggerimenti

If not escaping, you can also use single quotes for attribute values.

echo "<div id=srating><img src='images/soundimg.png' alt='Sound' height='35' width='35'></div>Sound: ".$dsrating['s_rating']."</div>";

If you need to echo and in string u need to put " quotes, you can use single quote around ur string.

echo '<div id=srating><img src="images/soundimg.png" alt="Sound" height="35" width="35"></div>Sound: '.$dsrating['s_rating'].'</div>';

same for single quote. But if you need both single & double quotes you can use any method and use \' or \"

Or you can have a very useful too, heredoc syntax.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top