Forum Moderators: coopster

Message Too Old, No Replies

MySQL Query Help

         

brettlaw

3:37 pm on Jun 27, 2005 (gmt 0)



I wonder in any one can help me,

I’m trying to create a query to display search results from a table in my MySql database that will return 4 results for each page shown.

Each item in the database has been assigned an automatic number so the latest item added has the highest number. The search results for the fist page need to start from the newest entry (the one with the highest number) and descend. The next page needs the query to start from the last item in the previous page query. Also the another problem is, the user has the option to remove items from the database so the numbering is not-consecutive as it descends.

i.e.

10, 9, 7, 6, 5, 4, 2, 1,
Numbers 8 and 3 are missing, so results for page one need to be = 10, 9, 7, 6,
Results for page two need to be = 5, 4, 2, 1

Thanks in advance, as I’ve been messing all day and can’t come up with a solution.

arran

4:05 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



Hi Brett,

If your table is of the form:

table_A(id_column,....)

You could use something like

$results_per_page = 4;
$result_page = <whatever>;
$start_from = $results_per_page * ($result_page - 1);
$sql_query = "select * from table_A order by id_column desc limit $start_from, $results_per_page";

Sarah Atkinson

5:44 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



I don't know if this would work but what aboult
nextpage button a hef would = <?php echo $_SERVER[PHP_SELF] . "?results=" . $mysqlresults . "?count=" . $count;?>

then have your sql statment select all with the order by desc

use a loop to echo off your 4 for each page and pass the counter (so you know where you left off ) in the $count variable.

I've never tried to pass results in a url before so i don't know if this will work.