Jump to content

php and onmouseover pop-up description


RobertSubnet

Recommended Posts

Hello all. I hope this is the right forum for this question.

 

I would like to have a pop-up description for a picture when the user moves their mouse pointer over the picture.

 

The code I had in mind would select the path to my pictures and their description stored in MySQL. Then use a while loop to retrieve the image paths. Something like this:

 

<?PHP
$query="select picture_path, description from my_table where picture = 'funny'";

mysql_query($query);

while (mysql_query) {

$picture_path = $row['picture_path'];
$description = $row['description'];

?>

<img src='<?php echo "$picture_path"; ?> onmouseover="<p class="my_class"><?php echo "$description"; ?></p>" />

<?php
echo '<br>';
//close while loop
}

?>

 

Would something like this work? Is there a better way to implement this?

 

Thank you for your suggestions.

 

 

Link to comment
https://forums.phpfreaks.com/topic/171043-php-and-onmouseover-pop-up-description/
Share on other sites

<?PHP
$query="select picture_path, description FROM my_table where picture = 'funny'";

mysql_query($query);

while (mysql_query) {

$picture_path = $row['picture_path'];
$description = $row['description'];

?>

<img src='<?php echo "$picture_path"; ?> onmouseover="<p class="my_class"><?php echo "$description"; ?></p>" />

<?php
echo '<br>';
//close while loop
}

?>

 

Would something like this work? Is there a better way to implement this?

 

Thank you for your suggestions.

There are many JavaScript functions out there on the web, for this simple tutorial, however I will use alert.

 

Use this in the <head> area or in an included javascript file:

 

<script type="text/javascript">
function showPopup(sMsg)
{
alert(sMsg);
}
</script>

 

 

Here is the PHP you could use.

<?php
$sQuery="SELECT picture_path, description FROM my_table WHERE picture = 'funny'";
$rResult = mysql_query($sQuery);

while ($aRow = mysql_fetch_array($rResult)) {
	$sFilePath = $aRow[0];
	$sDescription = $aRow[1];

	print '<img src="'. $sFilePath .'" onmouseover="showPopup(\''. $sDescription .'\');" />';
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.