Page 1 of 1
pagnation
Posted: Sat Jun 17, 2006 8:25 am
by corillo181
i'm trying to make a back bottom so when someone clicks it goest the the id that is less than the current one..
now i wonder why dont this work?
when ppl click on back it send the to the first id in the table..
Code: Select all
$month=$_GET['m'];
$curent_id=$_GET['p'];
$b=mysql_query("SELECT photo_id FROM tra_cotm_photo WHERE photo_id<$curent_id AND cotm_id='$month' LIMIT 1")or die(mysql_error());
$back=mysql_fetch_array($b);
echo '<a href='.$_SERVER['PHP_SELF'].'?m='.$_GET['m'].'&p='.$back['photo_id'].'>back</a>';
now this next bottom does work it sends ppl to te next id..
now they exctly the same so why dont they act the same?
Code: Select all
$month=$_GET['m'];
$curent_id=$_GET['p'];
$n=mysql_query("SELECT photo_id FROM tra_cotm_photo WHERE photo_id>$curent_id AND cotm_id='$month' LIMIT 1")or die(mysql_error());
$next=mysql_fetch_array($n);
echo '<a href='.$_SERVER['PHP_SELF'].'?m='.$_GET['m'].'&p='.$next['photo_id'].'>next</a>';
Posted: Sat Jun 17, 2006 8:59 am
by kendall
Yo man check this out
maybe its because when u
SELECT photo_id FROM tra_cotm_photo WHERE photo_id<$curent_id AND cotm_id='$month' LIMIT 1
MYSQL searches from the top of the database records and not necessary from where u left off
you probably need to do something like
Code: Select all
SELECT photo_id FROM tra_cotm_photo WHERE photo_id=$curent_id AND cotm_id='$month' LIMIT 1
where $current_id is a reference to the previous id u were on
Posted: Sat Jun 17, 2006 9:10 am
by printf
They are not the same....
By default MySQL ORDER BY is ASC so if you start at 5, the next SELECT if doing column_name > 5 would be 6 or the next highest number if the numbers are not in order, limited by your LIMIT = 1, so only 1 row is returned!
When you do the reverse, MySQL is still sorting in ASC, so the next result will always be the lowest numbered result because the sort starts at the lowest result, and not the next lowest result! That why it is a good idea to tell MySQL exactly what you want done.
Code: Select all
$month = mysql_real_escape_string ( $_GET['m'] );
$curent_id = intval ( $_GET['p'] );
$n = mysql_query ( "SELECT photo_id FROM tra_cotm_photo WHERE photo_id > " . $curent_id . " AND cotm_id = '" . $month . "' ORDER BY photo_id ASC LIMIT 1" ) or die ( mysql_error() );
$next = mysql_fetch_array ( $n, MYSQL_ASSOC );
echo '<a href=' . $_SERVER['PHP_SELF'] . '?m=' . $_GET['m'] . '&p=' . $next['photo_id'] . '>next</a>';
Code: Select all
$month = mysql_real_escape_string ( $_GET['m'] );
$curent_id = intval ( $_GET['p'] );
$b = mysql_query ( "SELECT photo_id FROM tra_cotm_photo WHERE photo_id < " . $curent_id . " AND cotm_id = '" . $month . "' ORDER BY photo_id DESC LIMIT 1" ) or die ( mysql_error() );
$back = mysql_fetch_array ( $b, MYSQL_ASSOC );
echo '<a href=' . $_SERVER['PHP_SELF'] . '?m=' . $_GET['m'] . '&p=' . $back['photo_id'] . '>back</a>';
pif!
Posted: Sat Jun 17, 2006 9:13 am
by corillo181
i dont think thats going to wokr thats just telling mysql to select the current id not the id behind that one.. i'm trying to the the id that goest before the current id..
like i said the next one works fine.. so what you said sounds like could be the problem, but the query you put doesn't help..
Posted: Sat Jun 17, 2006 9:17 am
by corillo181
prntf, i havent test it yet, but i'm very sure that will work it makes sense..
thanx man.
Posted: Sat Jun 17, 2006 9:18 am
by kendall
corillo181 wrote:i dont think thats going to wokr thats just telling mysql to select the current id not the id behind that one.. i'm trying to the the id that goest before the current id..
Well i meant
where $current_id is a reference to the previous id u were on
so pobably its like $current_id-- ?
Posted: Sat Jun 17, 2006 9:24 am
by printf
kendall wrote:so pobably its like $current_id-- ?
But if they are not in order or your on the first result, then doing $var--; would not be a option!
pif!
Posted: Sat Jun 17, 2006 9:37 am
by corillo181
any of you guysd know wher ei can find a good tutorial to make thumbnail of pictures, but keeping the aspect ratio?