[PHP] Re: displaying database results with forward and back buttons

2004-07-11 Thread John Taylor-Johnston
Finally something I can give back, made by my little lonesome with no help :)

 I have a query that returns lots of rows so I want to display the results in blocks 
 of 25 or so on my web page and have forward and back buttons to navigate the results.

include it first:

include(settings_limit.inc);

then set $offset and $limit in your sql

$sql = 'SELECT *,MATCH (field1,field2)
AGAINST (\''.$searchenquiry.'\' IN BOOLEAN MODE)
AS relevancy FROM '.$table.'
WHERE MATCH (field1,field2)
AGAINST (\''.$searchenquiry.'\' IN BOOLEAN MODE)
ORDER BY relevancy DESC
LIMIT '.$offset.','.$limit.';';

--settings_limit.inc
?php

#
## $mycounter is set by script calling settings_limit.inc 
#

#
### Set $offset  $limit 
#

if((!$offset) || ($offset  0))
{
$offset = 0;
}
$limit = 25;

#
### $nextinsert #
#
$new_offset = $offset + $limit;
$disp = $limit;
if ($new_offset + $limit  $mycounter)
{
  $disp = $mycounter - $new_offset;
}
if ($disp  0)
{
$nextinsert  = form ACTION=\.$SCRIPT_NAME.\ TARGET=\_top\ 
METHOD=\POST\tdNext .$disp. Requests input type=\submit\ name=\submit\ 
value=\\input type=\hidden\ name=\offset\ value=\.$new_offset.\input 
type=\hidden\ name=\table\ value=\.$table.\input type=\hidden\ name=\db\ 
value=\.$db.\;
 if($searchenquiry)
  $nextinsert  .= input type=\hidden\ name=\searchenquiry\ 
value=\.stripslashes(htmlspecialchars($searchenquiry)).\;
 if($scholarsenquiry)
  $nextinsert  .= input type=\hidden\ name=\scholarsenquiry\ 
value=\.$scholarsenquiry.\;
 if($titlesenquiry)
  $nextinsert  .= input type=\hidden\ name=\titlesenquiry\ 
value=\.$titlesenquiry.\;
 $nextinsert  .= /td/form;
}
#
### $previousinsert #
#

$new_offset2 = $offset - $limit;
if ($offset  0)  // can display previous msg
{
 $disp = $limit;
 $previousinsert  =  font face=\arial\ size=2A 
HREF=\index.html?submit=submitoffset=.$new_offset2.table=$tabledb=$db\lt;lt; 
Previous .$disp. Requests/a/font;

$previousinsert  = form ACTION=\.$SCRIPT_NAME.\ TARGET=\_top\ 
METHOD=\POST\tdinput type=\submit\  name=\submit\ value=\\ Previous 
.$disp. Requestsinput type=\hidden\ name=\offset\ 
value=\.$new_offset2.\input type=\hidden\ name=\table\ 
value=\.$table.\input type=\hidden\ name=\db\ value=\.$db.\;
 if($searchenquiry)
  $previousinsert  .= input type=\hidden\ name=\searchenquiry\ 
value=\.stripslashes(htmlspecialchars($searchenquiry)).\;
 if($scholarsenquiry)
  $previousinsert  .= input type=\hidden\ name=\scholarsenquiry\ 
value=\.$scholarsenquiry.\;
 if($titlesenquiry)
  $previousinsert  .= input type=\hidden\ name=\titlesenquiry\ 
value=\.$titlesenquiry.\;
 $previousinsert  .= /td/form;
}
#
### $lastinsert #
#

$new_offset3 = $mycounter - $limit;

if (($new_offset3  $limit) and ($offset != $mycounter - $limit))  // can display goto 
end msg
{
$lastinsert  = form ACTION=\.$SCRIPT_NAME.\ TARGET=\_top\ 
METHOD=\POST\tdGo To End input type=\submit\  name=\submit\ 
value=\|\input type=\hidden\ name=\offset\ value=\.$new_offset3.\input 
type=\hidden\ name=\table\ value=\.$table.\input type=\hidden\ name=\db\ 
value=\.$db.\;
 if($searchenquiry)
  $lastinsert  .= input type=\hidden\ name=\searchenquiry\ 
value=\.stripslashes(htmlspecialchars($searchenquiry)).\;
 if($scholarsenquiry)
  $lastinsert  .= input type=\hidden\ name=\scholarsenquiry\ 
value=\.$scholarsenquiry.\;
 if($titlesenquiry)
  $lastinsert  .= input type=\hidden\ name=\titlesenquiry\ 
value=\.$titlesenquiry.\;
 $lastinsert  .= /td/form;
}
#
### $firstinsert 
#

$new_offset4 = $mycounter - $limit;
if ($new_offset4  $limit)  // can display goto beginning msg
{
$new_offset4 = 0;
$firstinsert  = form ACTION=\.$SCRIPT_NAME.\ TARGET=\_top\ 
METHOD=\POST\tdinput type=\submit\ name=\submit\ value=\|\ Go To 
Beginninginput type=\hidden\ name=\offset\ value=\.$new_offset4.\input 
type=\hidden\ name=\table\ value=\.$table.\input type=\hidden\ name=\db\ 
value=\.$db.\;
 if($searchenquiry)
  $firstinsert .= input type=\hidden\ name=\searchenquiry\ 
value=\.stripslashes(htmlspecialchars($searchenquiry)).\;
 if($scholarsenquiry)
  $firstinsert .= input type=\hidden\ name=\scholarsenquiry\ 
value=\.$scholarsenquiry.\;
 if($titlesenquiry)
  $firstinsert .= input type=\hidden\ name=\titlesenquiry\ 

Re: [PHP] Re: displaying database results with forward and back buttons

2004-07-11 Thread i sidhu
The main part of code i m using for Forward and Backward is,
 
 
 
if($page  1)
{
$prev = ($page - 1);
echo a 
href=\.$_SERVER['PHP_SELF'].?page=$prevsearchfor=$searchforseek=$seekage1=$age1age2=$age2state=$statecountry=$country\
 TARGET=\_parent\Previous/anbsp;;
}
for($i = 1; $i = $total_pages; $i++)
{
if(($page) == $i)
{
echo $inbsp;;
} else
{
echo a 
href=\.$_SERVER['PHP_SELF'].?page=$isearchfor=$searchforseek=$seekage1=$age1age2=$age2state=$statecountry=$country\
 TARGET=\_parent\$i/anbsp;;
}
}
// Build Next Link
if($page  $total_pages)
{
$next = ($page + 1);
echo a 
href=\.$_SERVER['PHP_SELF'].?page=$nextsearchfor=$searchforseek=$seekage1=$age1age2=$age2state=$statecountry=$country\
 TARGET=\_parent\Next/a;
}

 
Change variables accroding to u.
 
 
 
John Taylor-Johnston [EMAIL PROTECTED] wrote:
Finally something I can give back, made by my little lonesome with no help :)

 I have a query that returns lots of rows so I want to display the results in blocks 
 of 25 or so on my web page and have forward and back buttons to navigate the results.

include it first:

include(settings_limit.inc);

then set $offset and $limit in your sql

$sql = 'SELECT *,MATCH (field1,field2)
AGAINST (\''.$searchenquiry.'\' IN BOOLEAN MODE)
AS relevancy FROM '.$table.'
WHERE MATCH (field1,field2)
AGAINST (\''.$searchenquiry.'\' IN BOOLEAN MODE)
ORDER BY relevancy DESC
LIMIT '.$offset.','.$limit.';';

--settings_limit.inc

#
## $mycounter is set by script calling settings_limit.inc 
#

#
### Set $offset  $limit 
#

if((!$offset) || ($offset  0))
{
$offset = 0;
}
$limit = 25;

#
### $nextinsert #
#
$new_offset = $offset + $limit;
$disp = $limit;
if ($new_offset + $limit  $mycounter)
{
$disp = $mycounter - $new_offset;
}
if ($disp  0)
{
$nextinsert = Next .$disp. Requests  [input] \ [input]  [input]  [input] ;
if($searchenquiry)
$nextinsert .=  [input] ;
if($scholarsenquiry)
$nextinsert .=  [input] ;
if($titlesenquiry)
$nextinsert .=  [input] ;
$nextinsert .= ;
}
#
### $previousinsert #
#

$new_offset2 = $offset - $limit;
if ($offset  0) // can display previous msg
{
$disp = $limit;
$previousinsert =   Previous .$disp. Requests;

$previousinsert =  [input]  Previous .$disp. Requests [input]  [input]  [input] ;
if($searchenquiry)
$previousinsert .=  [input] ;
if($scholarsenquiry)
$previousinsert .=  [input] ;
if($titlesenquiry)
$previousinsert .=  [input] ;
$previousinsert .= ;
}
#
### $lastinsert #
#

$new_offset3 = $mycounter - $limit;

if (($new_offset3  $limit) and ($offset != $mycounter - $limit)) // can display goto 
end msg
{
$lastinsert = Go To End  [input] |\ [input]  [input]  [input] ;
if($searchenquiry)
$lastinsert .=  [input] ;
if($scholarsenquiry)
$lastinsert .=  [input] ;
if($titlesenquiry)
$lastinsert .=  [input] ;
$lastinsert .= ;
}
#
### $firstinsert 
#

$new_offset4 = $mycounter - $limit;
if ($new_offset4  $limit) // can display goto beginning msg
{
$new_offset4 = 0;
$firstinsert =  [input]  Go To Beginning [input]  [input]  [input] ;
if($searchenquiry)
$firstinsert .=  [input] ;
if($scholarsenquiry)
$firstinsert .=  [input] ;
if($titlesenquiry)
$firstinsert .=  [input] ;
$firstinsert .= ;
}


#
### Display Inserts #
#

#
if (($previousinsert) or ($nextinsert))
#echo ;
echo ;

#if (($previousinsert) || ($nextinsert))
#echo (Sorted by id - $mycounter records found total);

if (($previousinsert) or ($nextinsert))
echo ;

if (($firstinsert) and ($offset != 0)) echo $firstinsert;

if ($previousinsert) echo $previousinsert;

if (($previousinsert)  ($nextinsert)) echo | ;

if ($nextinsert) echo $nextinsert;

if ($lastinsert) echo $lastinsert;

if (($previousinsert) or ($nextinsert))
#echo ;
echo ;

?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

 

-
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!

Re: [PHP] Re: displaying database results with forward and back buttons

2004-07-11 Thread Curt Zirzow
* Thus wrote John Taylor-Johnston:
 Finally something I can give back, made by my little lonesome with no help :)

heh.. we all started somewhere.

 
  I have a query that returns lots of rows so I want to display the results in 
  blocks of 25 or so on my web page and have forward and back buttons to navigate 
  the results.
 
 include it first:

I would strongly discourage posting and scripts you have, there are
serveral reasons why it shouldn't really be done besides that we
would have 1000's of posts that say.. here is my script...

But more importantly, i'd have to go through them all pointing out
all the wrong/bad things they did :D


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php