blogit Posted November 26, 2007 Share Posted November 26, 2007 Hello, i have a photo gallery installed and working i'm able to connect to the db and select data from tables to display on any other page of my site but I want to be able to display say 4 pictures on a page if I just copy/paste my code it ends up grabbing and displaying the same image 4 times over. Below is the code i'm using and the image tag. I connect fine and it displays images, I need to create a loop so that each time the pid (picture id) comes up it increments by 1, or maybe each instance of pid in the image tag is a unique number from 1-1000. There was a while loop included with the code but it wasn't working nor was much else of the code so i changed it around and now im stuck, if anyone can give me some advice id really appreciate it thanks $result = mysql_query("SELECT filename, filepath, pid FROM cpg14x_pictures WHERE pwidth > pheight ORDER BY RAND() LIMIT 4"); $obj = mysql_fetch_object($result); <img src="/Gallery/albums/<?php echo $obj->filepath; ?>thumb_<?php echo $obj->filename; ?>" id="thephoto_<?php echo $obj->pid; ?>" onLoad="initImage('thephoto_<?php echo $obj->pid; ?>')" alt="The Gallery" /> --------- The old loop that didn't work was to create a row after the 2nd and 4th picture for a small table, i know its missing a closing bracket for the while loop but it still wasn't working and i dont know what $i was. while($obj = mysql_fetch_object($result)){ $i = $i + 1; if ($i == 3 || $i == 5) } Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 26, 2007 Share Posted November 26, 2007 Have a look at this example http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Quote Link to comment Share on other sites More sharing options...
blogit Posted November 26, 2007 Author Share Posted November 26, 2007 Thanks I tested that code by having it output the picture id (pid) which works but i'm not sure how to insert the entire img tag into that echo/string, below is how it looks and its obviously not going to work what needs changing? echo "<td><img src="/Gallery/albums/<?php echo $obj->filepath; ?>thumb_<?php echo $obj->filename; ?>" id="thephoto_<?php echo $obj->pid; ?>" onLoad="initImage('thephoto_<?php echo $obj->pid; ?>')" alt="The Gallery" /></td>"; Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 26, 2007 Share Posted November 26, 2007 You can simply try this, I don't think <?php...?> inside a echo will work <td><img src="/Gallery/albums/<?php echo $obj->filepath; ?>thumb_<?php echo $obj->filename; ?>" id="thephoto_<?php echo $obj->pid; ?>" onLoad="initImage('thephoto_<?php echo $obj->pid; ?>')" alt="The Gallery" /></td> Quote Link to comment Share on other sites More sharing options...
blogit Posted November 26, 2007 Author Share Posted November 26, 2007 No it does't any other suggestions on inserting a random number where pid should be? Quote Link to comment Share on other sites More sharing options...
blogit Posted November 26, 2007 Author Share Posted November 26, 2007 Got this to work with the following code instead of echoing print worked out....Thanks for the link to that other code print '<td>'.'<div class="img-shadow">'.'<a href="/Gallery/displayimage.php?pos=-'.$pid.'">'.'<img src="/Gallery/albums/' . $filepath . 'thumb_' . $filename . '">'.'</a>'.'</div>'.'</td>'; 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.