RobertSubnet Posted August 19, 2009 Share Posted August 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/171043-php-and-onmouseover-pop-up-description/ Share on other sites More sharing options...
KevinM1 Posted August 19, 2009 Share Posted August 19, 2009 This link should send you on the right path: http://www.google.com/search?q=javascript+tooltip&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a Quote Link to comment https://forums.phpfreaks.com/topic/171043-php-and-onmouseover-pop-up-description/#findComment-902084 Share on other sites More sharing options...
Monadoxin Posted August 19, 2009 Share Posted August 19, 2009 <?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 .'\');" />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/171043-php-and-onmouseover-pop-up-description/#findComment-902086 Share on other sites More sharing options...
RobertSubnet Posted August 19, 2009 Author Share Posted August 19, 2009 Thanks Nightslyr and Monadoxin! I will give those a try. ~Robert Quote Link to comment https://forums.phpfreaks.com/topic/171043-php-and-onmouseover-pop-up-description/#findComment-902095 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.