include("dbconnect.php") ; $locsection_id = 1; $loccategory_id = 0; $locphoto_id = 0; $loctitle = ''; $locdate_text = ''; $loclocation = ''; $locprice = ''; $locabstract = ''; $locfilename = ''; $locorder_num = 0; if (isset($_GET["section_id"])) { $locsection_id = $_GET['section_id']; } switch ($locsection_id) { case "2": $label = "rocknroll"; break; case "3": $label = "flowers"; break; case "4": $label = "carousels"; break; case "5": $label = "landscapes"; break; } if (isset($_GET["category_id"])) { // set category_id from url $loccategory_id = $_GET['category_id']; // are we editing an existing category? if (isset($_GET["photo_id"])) { $locphoto_id = $_GET['photo_id']; } else { $qry_photo_text = "SELECT photo_id FROM tbl_photos WHERE category_id = ". $loccategory_id ." ORDER BY order_num, title LIMIT 1"; $qry_photo = mysql_query($qry_photo_text); While ($row = mysql_fetch_array($qry_photo)) { $locphoto_id = $row['photo_id']; } } } //get photo details $qry_photo_text = "SELECT title, date_text, location, price_desc, abstract, filename, order_num FROM tbl_photos WHERE photo_id = " .$locphoto_id; $qry_photo = mysql_query($qry_photo_text); if (!$qry_photo) { die('Invalid query: ' . mysql_error()); } While ($row = mysql_fetch_array($qry_photo)) { $loctitle = $row['title']; $locdate_text = $row['date_text']; $loclocation = $row['location']; $locprice_desc = $row['price_desc']; $locabstract = $row['abstract']; $locfilename = $row['filename']; $locorder_num = $row['order_num']; } $locphotocount = 1; $locphotoback = 0; $locphotonext = 0; $locposition = 1; //get all the photos $qry_photos_text = "SELECT photo_id FROM tbl_photos WHERE category_id = " .$loccategory_id ." ORDER BY order_num, title"; $qry_photos = mysql_query($qry_photos_text); if (!$qry_photos) { die('Invalid query yo: ' . mysql_error()); } //put the photo_id's in an array $photoarray = array(); $count = 0; While ($row = mysql_fetch_array($qry_photos)) { $photoarray[$count] = $row['photo_id']; $count++; } //get the number of photos in this category $locphotocount = count($photoarray); //find the current position in the array $position = 0; $i = 0; foreach ($photoarray as $value) { if($value == $locphoto_id){ $position = $i; } $i++; } //get the previous element in the array if($position > 0) { $locphotoback = $photoarray[$position-1]; } //get the next element in the array if($position < $locphotocount-1) { $locphotonext = $photoarray[$position+1]; } ?>