pagnation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
corillo181
Forum Commoner
Posts: 76
Joined: Wed Apr 26, 2006 3:02 pm

pagnation

Post 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>';
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post 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
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post 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!
corillo181
Forum Commoner
Posts: 76
Joined: Wed Apr 26, 2006 3:02 pm

Post 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..
corillo181
Forum Commoner
Posts: 76
Joined: Wed Apr 26, 2006 3:02 pm

Post by corillo181 »

prntf, i havent test it yet, but i'm very sure that will work it makes sense..

thanx man.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post 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-- ?
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post 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!
corillo181
Forum Commoner
Posts: 76
Joined: Wed Apr 26, 2006 3:02 pm

Post by corillo181 »

any of you guysd know wher ei can find a good tutorial to make thumbnail of pictures, but keeping the aspect ratio?
Post Reply