Jump to content

Problems with photo gallery...


JJohnsenDK

Recommended Posts

Hey

 

Im trying to make a photo gallery based on PHP and MySQL.

 

My problem is that im sorting out the pictures in the gallery by thier id number(download_id). It works great when i doesnt have hulls in my database. I mean if i have deleted a picture so the id number would go like this:

 

13, 14, 16, 17

 

Then when i hit number 15 it goes wrong. Can i somehow make php skip these hulls?

 

Here is my code as it looks at the moment:

 

<?php
$picQuery = mysql_query("SELECT download_title, download_url, download_description FROM ".$db_prefix."downloads WHERE download_id = '".$_GET['no']."' AND download_cat = '".$_GET['cat']."'");
$picRow = mysql_fetch_array($picQuery);

$countQuery = mysql_query("SELECT COUNT(download_id) AS total FROM ".$db_prefix."downloads WHERE `download_cat` = '".$_GET['cat']."'");
$countRow = mysql_fetch_array($countQuery);

$highQuery = mysql_query("SELECT download_id FROM ".$db_prefix."downloads WHERE `download_cat` = '".$_GET['cat']."' ORDER BY `download_id` DESC");
$highRow = mysql_fetch_array($highQuery);

$lowQuery = mysql_query("SELECT download_id FROM ".$db_prefix."downloads WHERE `download_cat` = '".$_GET['cat']."' ORDER BY `download_id`");
$lowRow = mysql_fetch_array($lowQuery);
?>
<table width='100%' class='storybox'>
    <tr>
        <td>
            <table width='100%'>
                <tr align='left' class='table-cellpic'>
                    <th colspan='3'>Billedegalleri - <?php echo $picRow['download_title']; ?></th>
                </tr>
            </table>
		<div class="gallery_main">
			<div class="gallery_picture">
				<img src="<?php echo $picRow['download_url']; ?>" width="500" alt="" />
			</div>
			<?php

			?>
			<div class="gallery_navigation">
				<?php

				?>
				<p><a href="gallery.php?no=<?php echo $_GET['no'] - 1; ?>&cat=<?php echo $_GET['cat']; if($_GET['no'] <= $lowRow['download_id']){ echo "\"></a>Forrige";} else{ ?>">Forrige</a><?php } ?> - <a href="gallery.php?no=<?php echo $_GET['no'] + 1; ?>&cat=<?php echo $_GET['cat']; if($_GET['no'] >= $highRow['download_id']){ echo "\"></a>Næste";} else{ ?>">Næste</a><?php } ?></p>
			</div>
			<div class="gallery_title">
				<p><b><?php echo $picRow['download_title']; ?></b></p>
			</div>
			<div class="gallery_description">
				<p><?php echo $picRow['download_description']; ?></p>
			</div>
			<div>
				<p>
					<?php
						echo $countRow['total'];
						echo "<br />";
						echo $highRow['download_id'];
						echo "<br />";
						echo $lowRow['download_id'];
					?>
				</p>
			</div>
		</div>
	</td>
</tr>
</table>
?>

Link to comment
Share on other sites

erm...

 

Im not asking for how i can download an image, its just a image view gallery...

 

Im asking for how i get PHP to skip that hull that can acour in the database...

 

Exampel:

 

Database:

table: picture

row: picture_id

colum: 1, 2, 4, 5, 8 and so on

 

As you can see the numbers 3, 6 and 7 are missing and as you can see in the

script i posted above im using the picture_id to select which picture i want

to view on the screen.

 

I -1 to the $_GET['id'] variable everytime the link "Forrige" (Last in danish) and

+1 when "Næste" (next in danish) is clicked.

 

So its a problem if $_GET['id'] = 2 and i then click "Næste" because then

$_GET['id'] = 3 and picture_id: 3 does not exists in database

then no image are shown.

 

How do fix this problem?

Link to comment
Share on other sites

hows this for an example... assume $row[numbers]='|1|2|4|6|7|';

 

$numbers=explode("|",$row[numbers]);
$i=0;
foreach($numbers as $val){
$out.='<a>'.$val.'</a>';
}
echo $out;

 

then when you delete an image, just query for fields...

$query=mysql_query("SELECT * FROM `` WHERE `numbers`='%|$num|%'");
while($row=mysql_fetch_assoc($query)){
$row[numbers]=explode("|",$row[numbers]);
unset($row[numbers][array_search($num, $row[numbers])]);
$row[numbers]=implode("|",$row[numbers]);
mysql_query("UPDATE `` SET `numbers`='$row[numbers]' LIMIT 1");
}

and done and done :-)

Link to comment
Share on other sites

i think i explained my self badly about the database. The database looks like this:

 

Table name:

downloads

 

Rows:

download_id and download_url

 

Colums:

1 and images/downloads/soccer1.jpg

2 and images/downloads/soccer2.jpg

3 and images/downloads/soccer3.jpg

 

and so on...

 

Then i cant use the while loop you suggested, right?

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.