im using 2 variables $start and $amount which are used to limit my search to
say ..10 rows.
but then i check to see if there are more rows in the database ...if there
is i have a button appear to offer the user to search through the next ten
rows...
this works fine if im prepared to have the results displayed on differant
pages but of course i could end up having to have hundreds of pages.
how do i submit the query so it apears on the same page?
heres a clip of my code.
thanks chris
mysql_select_db("surfing",$connect);
$result =mysql_query ("select * from sale_items order by date desc limit
$start, $amount ",$connect);
// user ,items ,email,make ,model,year ,condition ,price ,description
,date
// from sale_items",$connect);
$the_result =mysql_query ("select * from sale_items order by date desc
",$connect);
if($amount != mysql_num_rows($the_result)) {
$start = $start+3;
$amount = $amount+3;
echo"<a
href='test4sale.php?start=$start&amount=$amount&type=next'>Next</a>";
Why not always increase $amount by 1, then check to see if
mysql_num_rows returns $amount + 1? If it does, simply ignore that last row
when returning data (return $amount rows), and pass $start + $amount + 1 on
as $start. So your code might look something like this:
mysql_select_db ("surfing",$connect);
$tamount = $amount + 1;
$result = mysql_query ("select * from sale_items order by date desc limit
$start, $tamount ", $connect);
if ($tamount == mysql_num_rows ($result)) {
$start = $start + $amount + 1;
echo ("<a href='test4sale.php?start=$start&amount=$amount&type=next'>Next
$amount Results</a>");
}
Cheers!
Jeff Walter
je...@jeffs-place.org
PS - I didn't try this code, but it *should* work
anyway ..ihave no problem finding out if there are more rows the problem is
that if there is, i want the next query to increment the limit set by the
first query by 20 each time so that the next 20 rows are shown displayed on
the same page when the next btn is clicked.....as in the google style search
results.
im sorry i know this probably dosnt look clear at all....
anyway thanks chris
"Jeff Walter" <je...@jeffs-place.org> wrote in message
news:WH6Z8.33040$Wt3.29414@rwcrnsc53...
Okay...Now I know what you want... (even though on a recent visit to Google
I didn't get this functionality) ...
My idea is this...Add one more variable to your URL, we'll call it
$howmanypages for simplicity's sake. What you'll end up doing is
"repeating" your query. Code has been provided (I modified the original
code I posted).
mysql_select_db ("surfing",$connect);
for ($s = 1; $s <= $howmanypages; $s++) {
$tstart = $start + $amount * $s;
$result = mysql_query ("select * from sale_items order by date desc
limit $tstart, $amount ", $connect);
// Display your query results here //
// Add a "page" seperator if you want //
if ( $s == $howmanypages ) { // This is the last page being displayed
//
$tamount = $amount + 1;
$result = mysql_query ("select * from sale_items order by date desc
limit $tstart, $tamount ", $connect);
if ($tamount == mysql_num_rows ($result)) { // More results after
this last page //
$howmanypages = $howmanypages + 1;
echo ("<a
href='test4sale.php?start=$start&amount=$amount&type=next&howmanypages=$howm
anypages'>Next $amount Results</a>");
}
}
}
Hopefully this helps. Let me know if the code works for you.
Jeff Walter
je...@jeffs-place.org
itll take me a while to digest that ...ill try to put it in action sometime
this week
cheers chris
"Jeff Walter" <je...@jeffs-place.org> wrote in message
news:sgbZ8.11380$_51....@rwcrnsc52.ops.asp.att.net...
> thanks jeff
>
> itll take me a while to digest that ...ill try to put it in action
sometime
> this week
>
> cheers chris
I have a site on Lycos I am using to practice using PHP and have
written a script which does almost what you want. It works for me. You
might want to have a look at
http://members.lycos.co.uk/billemmott/scripts.php?page_no=1 and see
the Full Article for "Fixed Number Of Items Per Page ".
Hope it might help
--
Bill Emmott
If at first you dont succeed - read the instructions