Sebastian Ong Sebastian Ong - 3 years ago 55
HTML Question

Error in my HTML codes when trying to place in PHP

This is my HTML code for an image where I can hover over and view another picture

<a href="ProductDetail.php?cat_id=1"><img class = "images" src = "images/menTop pic1.jpg" onmouseover = "src = 'images/menTop pic1 hover.jpg'" onmouseout = "src = 'images/menTop pic1.jpg'"></a>


I tried to put it in my PHP and replace the IDs and picture with variables but I cannot seem to get it working due to the insane amount of " and '.

echo "<a href='ProductDetail.php?cat_id=".$itemid."'><img class = 'images' src = '".$imagefile."' onmouseover = 'src = '".$imagefile2."'' onmouseout = 'src = '".$imagefile."''></a>";


As of now it shows the first image but does not show the second image when I hover over the picture. Can anyone help me solve this problem? Appreciate the help, thanks!

EDIT:
$mysql = new mysqli("localhost", "root", null, "webdb");

$stmt = $mysql ->prepare("select itemid, itemname, imagefile, imagefile2, itemprice, itemcolor from webdb.item ORDER by itemid ASC");
$stmt->execute();
$stmt->bind_result($itemid, $itemname, $imagefile, $imagefile2, $itemprice, $itemcolor);

$column = 1;

echo "<div class = content>";
echo "<table align = 'center' style = 'width:80%'>";
while($stmt->fetch()) {
if ($column == 1) {
echo "<tr>";
}
echo "<th>";
echo "<a href='ProductDetail.php?cat_id=".$itemid."'><img class = 'images' src = '".$imagefile."' onmouseover = 'src = '".$imagefile2."'' onmouseout = 'src = '".$imagefile."''></a>";
echo "<a href='ProductDetail.php?cat_id=".$itemid."'><h4>".$itemname."</h4></a>";
echo "<p>".$itemcolor."</p>";
echo "<p>".$itemprice."</p>";
echo "</th>";

if ($column == 3) {
$column = 1;
echo "</tr>";
}
else {
$column++;
}
}

echo "</table>";
echo "</div>";
$stmt->close();
$mysql->close();


Currently, this is my block of codes where I am trying to extract every row of data from my item database and to place it nicely in columns of 3 in a webpage. Therefore, if there is a way of placing it in HTML instead of PHP, I'd love if you guys can teach me how to.

Answer Source
<?php echo'<a href ="ProductDetail.php?cat_id='.$itemid.'"><img class="images" src="'.$imagefile.'"
  onmouseover="src=\''.$imagefile2.'\';"
  onmouseout="src=\''.$imagefile.'\';"/></a>'; ?>

This should solve your problem

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download