PHP код:
<?php
mysql_connect("hs-test.urbanart.ptyc.org", "hs_test", "asdasd") or die(mysql_error());
mysql_select_db("hs_test") or die(mysql_error());
//get category-----------------------------------
$pi = $_GET['kep'];
$pic = substr($pi,0,strrpos($pi,'.'));
$result = mysql_query("SELECT * FROM gallery WHERE photo='".$pic."'") or die(mysql_error());
$row = mysql_fetch_array( $result ) ;
$cat = $row['category'];
//get last photo-----------------------------------
$result = mysql_query("SELECT MAX(id) FROM gallery WHERE (category='".$cat."' and vote = '0')") or die(mysql_error());
$row = mysql_fetch_array( $result );
$las = $row['MAX(id)'];
$result = mysql_query("SELECT * FROM gallery WHERE id='".$las."'") or die(mysql_error());
$row = mysql_fetch_array( $result );
$last = $row['photo'];
//get first photo----------------------------------
$result = mysql_query("SELECT MIN(id) FROM gallery WHERE (category='".$cat."' and vote = '0')") or die(mysql_error());
$row = mysql_fetch_array( $result );
$firs = $row['MIN(id)'];
$result = mysql_query("SELECT * FROM gallery WHERE id='".$firs."'") or die(mysql_error());
$row = mysql_fetch_array( $result );
$first = $row['photo'];
//check if it is last or first photo
if ($pic == $last) {
$pos = "last";
} elseif ($pic == $first) {
$pos = "first";
} else {
$pos = "no";
}
//get previous photo form same category
while ($prcat != $cat) {
$pr = $pic-1;
$result = mysql_query("SELECT * FROM gallery WHERE photo='".$pr."'") or die(mysql_error());
$row = mysql_fetch_array( $result ) ;
$prcat = $row['category'];
}
?>
обястите - по4ему он входит тут
PHP код:
while ($prcat != $cat) {
$pr = $pic-1;
$result = mysql_query("SELECT * FROM gallery WHERE photo='".$pr."'") or die(mysql_error());
$row = mysql_fetch_array( $result ) ;
$prcat = $row['category'];
}
в бесконе4ный цыкл?
p.s.: mysql table: hzzp://hungarianstreets.ws/mysql.zip > category is 4th column, photo is 2nd, id is 1st