JJohnsenDK Posted April 26, 2007 Share Posted April 26, 2007 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> ?> Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted April 26, 2007 Author Share Posted April 26, 2007 Any help would be nice guys... Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 26, 2007 Share Posted April 26, 2007 erm... I can't really see any link in there to allwo you to download an image... you need to only output a link to an image that can be downloaded. Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted April 27, 2007 Author Share Posted April 27, 2007 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? Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted April 27, 2007 Author Share Posted April 27, 2007 Anyone?? Quote Link to comment Share on other sites More sharing options...
taith Posted April 27, 2007 Share Posted April 27, 2007 where is that list of numbers in that code? i'm not showing any loops there atall...? Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted April 27, 2007 Author Share Posted April 27, 2007 i tired with loops... how would you make the loop in this script? cause i cant figure out how to make one that works Quote Link to comment Share on other sites More sharing options...
taith Posted April 27, 2007 Share Posted April 27, 2007 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 :-) Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted April 27, 2007 Author Share Posted April 27, 2007 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? Quote Link to comment Share on other sites More sharing options...
taith Posted April 27, 2007 Share Posted April 27, 2007 sure ya can... just... while($row=mysql_fetch_assoc($query)){ if(file_exists($row[download_url])){ echo $row[download_id]; } } 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.