Re: [PHP] << Previous n Articles
On Wednesday 06 February 2002 12:02, jtjohnston wrote: > Jason, > > I'm not ssure I follow. > $offset is the number i read in in my > $limit is the number displayed. > $num_rows is the number of rows in my database. Correct. > What are you doing with $previous? $previous would be my string, not the > previous offset? > Could you show me again? OK, you're stepping through your results and displaying $limit number of records each time. $offset holds your current place inside that set of results. To get to your next set of results you're adding $limit to $offset each time. So how do you get the previous set of results? Subtract $limit from $offset! > > > if(!$offset) > > > { > > > $offset = 0; > > > } > > > $limit = 5; > > > $num_rows = 13;#I get this from a mysql operation > > > > > > # > > > $new_offset = $offset + $limit; > > > $disp = $limit; > > > if ($new_offset + $limit > $num_rows) > > > { > > > $disp = $num_rows - $new_offset; > > > } > > > if ($disp > 0) > > > { > > > $nextinsert = " > > > HREF=\"index.html?offset=".$new_offset."\">Next ".$disp." Articles > > >>\n"; > > > > > } > > > > Something like: > > > > $previous = $offset - $limit; > > if ($previous < 0) { $previous = 0; } > > > > then incorporate $previous into your previous link in a similar fashion > > to the next link. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* A fail-safe circuit will destroy others. -- Klipstein */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] << Previous n Articles
Jason, I'm not ssure I follow. $offset is the number i read in in my $limit is the number displayed. $num_rows is the number of rows in my database. What are you doing with $previous? $previous would be my string, not the previous offset? Could you show me again? > > if(!$offset) > > { > > $offset = 0; > > } > > $limit = 5; > > $num_rows = 13;#I get this from a mysql operation > > > > # > > $new_offset = $offset + $limit; > > $disp = $limit; > > if ($new_offset + $limit > $num_rows) > > { > > $disp = $num_rows - $new_offset; > > } > > if ($disp > 0) > > { > > $nextinsert = " HREF=\"index.html?offset=".$new_offset."\">Next ".$disp." Articles > >>\n"; > > } > > > > Something like: > > $previous = $offset - $limit; > if ($previous < 0) { $previous = 0; } > > then incorporate $previous into your previous link in a similar fashion to > the next link. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] << Previous n Articles
On Wednesday 06 February 2002 09:59, jtjohnston wrote: > I'm using this code to create a "Next n Articles >>" on my index.page > from my mysql database. > I worked most of it out myself. Then I got some help. It works. I > thought I understood my own code enough to be able to construct a "<< > Previous n Articles". I guess not. My coding skills need help. > So how do I reverse my code to construct the previous n articles from my > sql database. > > if(!$offset) > { > $offset = 0; > } > $limit = 5; > $num_rows = 13;#I get this from a mysql operation > > # > $new_offset = $offset + $limit; > $disp = $limit; > if ($new_offset + $limit > $num_rows) > { > $disp = $num_rows - $new_offset; > } > if ($disp > 0) > { > $nextinsert = " HREF=\"index.html?offset=".$new_offset."\">Next ".$disp." Articles > >>\n"; > } > Something like: $previous = $offset - $limit; if ($previous < 0) { $previous = 0; } then incorporate $previous into your previous link in a similar fashion to the next link. hth -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* Random, n.: As in number, predictable. As in memory access, unpredictable. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] << Previous n Articles
I'm using this code to create a "Next n Articles >>" on my index.page from my mysql database. I worked most of it out myself. Then I got some help. It works. I thought I understood my own code enough to be able to construct a "<< Previous n Articles". I guess not. My coding skills need help. So how do I reverse my code to construct the previous n articles from my sql database. if(!$offset) { $offset = 0; } $limit = 5; $num_rows = 13;#I get this from a mysql operation # $new_offset = $offset + $limit; $disp = $limit; if ($new_offset + $limit > $num_rows) { $disp = $num_rows - $new_offset; } if ($disp > 0) { $nextinsert = " Next ".$disp." Articles >>\n"; } Thanks if you have a second. John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php