Jump to content

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 .'\');" />';
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.