Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript inside foreach loop
    text
    copied!<p>Suppose you have some code which includes a javascript tooltip, and a php foreach ($result as $row) loop which is calling values from an sql database like so,</p> <pre><code> &lt;?php foreach ($result as $row) { $link = $qs-&gt;link($row,'item'); $logoImage = $qs-&gt;getLogo($row-&gt;file_id); echo "&lt;ul class=\"imggrid\"&gt;&lt;li&gt;&lt;a class=\"ItemLink\" href=\"$link\"&gt;&lt;img width=\"80\" height=\"80\" src=\"" . $logoImage . "\" /&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;"; ?&gt; &lt;script type="text/javascript"&gt; jQuery(function() { jQuery( document ).tooltip({ hide: "true", show: "false", content: function() { if ( jQuery(this).is( "img[src='&lt;?php echo $logoImage ?&gt;']" ) ) { return "&lt;img class='map' src='&lt;?php echo $logoImage ?&gt;'&gt;&lt;a&gt;&lt;?php echo $qs-&gt;abbreviate($row-&gt;title,50); ?&gt;&lt;/a&gt;"; } } }); }); &lt;/script&gt; &lt;?php } ?&gt; </code></pre> <p>This is oversimplified but the php spits out a grid of pictures, and I want the tooltip to display a bigger version of each picture as it hovers. Right now it only displays the first picture in the grid for all the pictures. I am assuming it is because the script is outside the loop. But can I throw the script in the foreach loop?</p> <p>Any suggestions or help would be great. Keep in mind I am a novice at this stuff.</p> <p>EDIT: I added the part of my code in question.</p> <p>EDIT 2: Okay I've updated this code but now it is displaying nothing. I thought this would work since I am selecting img elements with src = $logoImage, where $logoImage spits out the address of the file.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload