Jump to content

[SOLVED] Need a loop


blogit

Recommended Posts

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)

}

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>';

 

Link to comment
Share on other sites

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.