dfez44 Posted July 8, 2011 Share Posted July 8, 2011 So what I am trying to do is have clicking on a thumbnail do two things at once. Make the larger image go into the iframe on my page and change the caption text to the appropriate caption. Is there anyway to do this is php, I realize onclick is not compatible. <?php $results= mysql_query ("SELECT * FROM `gallery` WHERE `remove`=0 AND `category`=1 ORDER BY `order` DESC"); while($result= mysql_fetch_array($results)){ echo " <a href='assets/".$result["img"]."' target='main'><img src='assets/thumbs/".$result["img"]."' alt='headshot1' onclick='MM_setTextOfLayer(\'caption'\,'','".$result["caption"]."')' class='th' /></a> "; } ?> [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 8, 2011 Share Posted July 8, 2011 If the image and caption are both within the iframe (shudder) then you just need to create the thumb as a link such that it uses the iframe as a target and pass it a URL such that the php page called can get the image. Example: <A href="getImage.php?id=12"><image src="image.jpg" /></a> Then create the PHP page to use that value on the query string to query for the image and caption. Quote Link to comment Share on other sites More sharing options...
dfez44 Posted July 10, 2011 Author Share Posted July 10, 2011 Well the caption doesn't need to be in the iframe, the main photo doesn't really need to be. But is there a way to have my thumbs have a main image appear in the same page with a caption at the same time? Quote Link to comment Share on other sites More sharing options...
dfez44 Posted July 10, 2011 Author Share Posted July 10, 2011 Ok so doing it a new page I am having trouble getting the id to transfer. Any suggestions? Here is the url http://rachelhippert.com/test/gallery.php. The code from my gallery page: <?php $results= mysql_query ("SELECT * FROM `gallery` WHERE `remove`=0 AND `category`=1 ORDER BY `order` DESC"); while($result= mysql_fetch_array($results)){ echo " <a href= 'postImg.php?id=".$result["id"]."' target='main'><img src='assets/thumbs/".$result["img"]."' class='th' /></a> "; } ?> And here is the 'postImg.php' code: <?php require("connect.php"); $id= $_GET["id"]; $results= mysql_query ("SELECT * FROM `gallery` WHERE `remove`=0 AND `category`=1 AND WHERE `id`=$id"); echo "<div class= 'img' align= 'center'> <img src='../assets/".$result["img"]."'><br/><p>".$result["caption"]."</p></div>"; ?> Quote Link to comment Share on other sites More sharing options...
dfez44 Posted July 12, 2011 Author Share Posted July 12, 2011 any suggestion? Im close but still unable to get my image and caption to show up. Any response would be hugely appreciated! Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 12, 2011 Share Posted July 12, 2011 You've posted code, but neither stated what you expect that code to do or what it is currently doing wrong. Are you getting errors, a blank page, what? Did you even check the HTML source code to verify that the links were being created with the right values? The only thing I see wrong is that you have two WHERE statements in your query. You would have caught that if you added error handling to your code.. Here is a rewrite of your code above with some debugging and error handling added. $query = "SELECT `id`, `img` FROM `gallery` WHERE `remove`=0 AND `category`=1 ORDER BY `order` DESC"; $result = mysql_query($query); if(!$result) { echo "Error running query: {$query}<br>\n"; echo "Error: " . mysql_error(); } elseif(mysql_num_rows($result)==0) { echo "No images found.<br>\n"; } else { while($row = mysql_fetch_assoc($results)) { ##DEBUG ONLY LINE echo " [id={$result['id']}]:"; echo "<a href= 'postImg.php?id={$row['id']}' target='main'><img src='assets/thumbs/{$row['img']}' class='th' /></a>\n"; } require("connect.php"); $id = $_GET["id"]; ##DEBUG ONLYLINE echo "GET['id'] = {$id}<br>"; $query = "SELECT `img`, `caption` FROM `gallery` WHERE `id`={$id}"; $result = mysql_query ($query); if(!$result) { echo "Error running query: {$query}<br>\n"; echo "Error: " . mysql_error(); } elseif(mysql_num_rows($result)==0) { echo "No image found.<br>\n"; } else { $row = mysql_fetch_assoc($result); echo "<div class= 'img' align= 'center'> <img src='../assets/{$row['img']}'><br/><p>{$row['caption']}</p></div>\n"; } Quote Link to comment Share on other sites More sharing options...
dfez44 Posted July 13, 2011 Author Share Posted July 13, 2011 Thank you for your help! It is all working now. Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 13, 2011 Share Posted July 13, 2011 I forgot to add, the you should use mysql_real_escape_string() on the id value coming from the URL. Otherwise you are open to SQL Injection - potentially compromising your entire database. Use this: $id = mysql_real_escape_string(trim($_GET['id'])); Quote Link to comment Share on other sites More sharing options...
dfez44 Posted July 13, 2011 Author Share Posted July 13, 2011 Good idea, thanks! Quote Link to comment 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.