Jump to content

[SOLVED] Image gallery repeating same image?


selliott

Recommended Posts

I'm putting together a simple image gallery, but I can't figure out how to get it to display ALL the images with a specific CatID.  This is what I've pieced together, but it just keeps repeating the same image.

 


<?php 
$CatID = $_REQUEST['CatID'];
$Photos = mysql_query("SELECT ID, Title, ImageURL, CatID, Details FROM Photo WHERE CatID='$CatID'", $connection) or die("error querying database");
$rows_nb = mysql_num_rows($Photos);

$pic_num = 0;
$pic_code = mysql_fetch_array($Photos);


					echo '<table width="75%" border="0" align="center">'; 

					while($row = mysql_fetch_assoc($Photos))


					{ 
						echo '<tr>'; 

						for ($tb_rows=0;$tb_rows<3;$tb_rows++) 
						{

							if ($pic_num < $rows_nb)
							{ 
							echo '<td><div align="center"><img src="'.$pic_code['ImageURL'] .'" border="1" /></div></td>';
							$pic_num++;
							}else{
							echo '<td></td>';
							}

						} 

					echo '</tr>'; 
					} 

					echo '</table>';
?>

Link to comment
Share on other sites

bwawhahahaha...

let me laugh to myself..

 

simple.. try add random after catid

example:

mypic.php?catid=3

change into

mypic.php?catid=3&time=3648364

fyi: 3648364 is random number

 

it happen 2 me.. and i don't know why my image always repeated..

 

fyi.. my script for image like this

 

mypic.php?id=134

 

and i try 2 upload new image to id 134..

when i refresh.. WAKZZZ the image don't shown right T_T

 

and i discover about cache .. cache that always browser do in soo you can save a lot space and time with it.

 

and that's the reason i give the answer

Link to comment
Share on other sites

bwawhahahaha...

let me laugh to myself..

 

simple.. try add random after catid

example:

mypic.php?catid=3

change into

mypic.php?catid=3&time=3648364

fyi: 3648364 is random number

 

it happen 2 me.. and i don't know why my image always repeated..

 

fyi.. my script for image like this

 

mypic.php?id=134

 

and i try 2 upload new image to id 134..

when i refresh.. WAKZZZ the image don't shown right T_T

 

and i discover about cache .. cache that always browser do in soo you can save a lot space and time with it.

 

and that's the reason i give the answer

 

Maybe I'm misunderstanding what you're saying (sorry if I am), but changing gallery.php?CatID=1  to gallery.php?CatID=1&time=23423 doesn't change anything.  I click on a gallery link on one page (photos.php), which inserts the Category ID in the URL (CatID=1 in this example), then when I get to that gallery page I have the script on that page pulling out the images from the photos table in the db with a category ID (CatID) that matches that category's ID.  I'm guessing it just ignores everything in the url string except the CatID?

Link to comment
Share on other sites

This is still not how I would personally do it, it's just the easiest way to fix your code so you can do what you want...

 

<?php

// mysql connection and select db here

// you should validate this variable...

$CatID = $_REQUEST['CatID'];

$Photos = mysql_query ( "SELECT ID, Title, ImageURL, CatID, Details FROM Photo WHERE CatID= '" . $CatID. "';", $connection ) or die ( "error querying database" );

if ( mysql_num_rows ( $Photos ) > 0 )
{
$coulmns = 3;
$start   = 0;
$data    = '';

echo '<table width="75%" border="0" align="center">'; 

while ( $row = mysql_fetch_assoc ( $Photos ) )
{
	$data .= '<td><div align="center"><img src="' . $row['ImageURL'] . '" border="1" /></div></td>';

	$start++;

	// table row is done, build it and dump it

	if ( $start == $columns )
	{
		$start = 0;

		echo '<tr>' . $data . '</tr>';

		$data = '';
	}
}

// fix any offset columns to keep the table columns in line

if ( $start != 0 )
{
	for ( $i = $start; $i <= $coulmns; $i++ )
	{
		$data .= '<td></td>';
	}

	echo '<tr>' . $data . '</tr>';

	unset ( $i );
}

echo '</table>';

unset ( $columns, $start, $data, $row );
}

mysql_free_result ( $Photos );

?>

Link to comment
Share on other sites

wakakakaka.. i'm a fool.. in here..

if you laugh to me.. i will accept it

 

>>$pic_code = mysql_fetch_array($Photos);

this goes line before while($row=mysql_fetch_array($Photos))

and below is always repeating again and again..

TS should type this

<?php 
$CatID = $_REQUEST['CatID'];
$Photos = mysql_query("SELECT ID, Title, ImageURL, CatID, Details FROM Photo WHERE CatID='$CatID'", $connection) or die("error querying database");
$rows_nb = mysql_num_rows($Photos);


$pic_num = 0;
$pic_code = mysql_fetch_array($Photos);

echo '<table width="75%" border="0" align="center">'; 

while($row = mysql_fetch_assoc($Photos))
{ 
$pic_code =$row; //wakakaka... this is the problem
echo '<tr>'; 

for ($tb_rows=0;$tb_rows<3;$tb_rows++) 

{

if ($pic_num < $rows_nb)

{ 

echo '<td><div align="center"><img src="'.$pic_code['ImageURL'] .'" border="1" /></div></td>';

$pic_num++;


}else{

echo '<td></td>';

}

} 

echo '</tr>'; 

} 

echo '</table>';
?>

i think i know what TS want.. but the above replies is the correct ^^

 

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.