WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : html split bar used to split in multiple pages a database result
Categories : HTML and PHP, Databases, MySQL, PHP Click here to Update Your Picture
Fabien HADDADI
Date : May 10th 2000
Grade : 1 of 5 (graded 1 times)
Viewed : 12393
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Fabien HADDADI
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 


This module prints a common split href menu, like those used to
display into several pages the results of a search engine.

For example, you have a page results.php3 that prints a collection
of results, and for more convenience you want to write several pages
from this result, each grouping MAXHIT results. So you paste this code
into a file split.php3, then you write in results.php3: include("[...]/split.php3");
at the exact location where you want the split bar to display.

Don't forget to modify your results page results.php3 to display
only the results i to i+MAXHIT-1 !

***
A live example can be seen at http://tropicalm.free.fr/pub/world/gallery/gallery.php3
***

*******************************************************************************
Code of split.php3:
*******************************************************************************

arguments: _maxelmt: number of elements in the collection
MAXHIT : number of max hits for a page
p : current page to be seen
cat (optional): optional parameters to send at return

<?
/*if MAXHIT=0 print a message error*/

if(!$MAXHIT) {
print "MAXHIT=0 : no split available!\n";
}

else {
if($res && $_maxelmt) {
$end=$p*$MAXHIT;
if($_maxelmt < $p*$MAXHIT)
$end=$_maxelmt;

print "\t\t Results ".(max(1,($p-1)*$MAXHIT+1)). '-'.$end. '  <br>'. "\n";
}

/*bypass if there's no more than one page*/
if ($_maxelmt> $MAXHIT) {
/* pattern: Results i'-i'+MAXHIT [<<Prev] | 1 --page+1 [2 --page+2 ...] | [Next>>] Page
i of n */

/*<<Prev*/
/*if p > 1, Prev is active, otherwise it's not*/
print "\t\t<font face='Arial' size='1'";

if (!($p-1)) {
print " color='#646464'><<Prev | \n"; } /*light gray*/
else {
/*prev*/
$prevpage=$p-1;
$anurl = "results.php3?_maxelmt=$_maxelmt&MAXHIT=$MAXHIT&p=$prevpage&$cat";
print " color='#008000' ><a href=$anurl><<Prev</a> | \n"; }
print "\t\t</font>". "\n";

/*print a page number every MAXHIT*/
for($i=0;$i<$_maxelmt;$i+=$MAXHIT) {
/*page number i+1*/
$pi=($i/$MAXHIT)+1;

/*don't activate current page's href*/
if($pi==$p) {
print "<font face ='Arial' size='1' color=#646464>$pi ";
}
else {
$anurl = "results.php3?_maxelmt=$_maxelmt&MAXHIT=$MAXHIT&p=$pi&$cat";
print "<font face ='Arial' size='1' color=#008000 >\n";
print "\t\t<a href=$anurl>".$pi. ' </a>'. "\n";
}
print "\t\t</font>". "\n";
}
/*Next>>*/
/*if p*MAXHIT doesn't meet or exceed MAXHIT, Next is active, otherwise it's not*/
print "\t\t<font face ='Arial' size='1'";

if (($_maxelmt-$p*$MAXHIT) <= 0) {
print " color='#646464'>| Next>>\n"; } /*light gray*/
else {
/*next*/
$nextpage=$p+1;
$anurl = "results.php3?_maxelmt=$_maxelmt&MAXHIT=$MAXHIT&p=$nextpage&$cat";
print ">| <a href=$anurl>Next>></a>\n";}
print '</font>';
}

if($_maxelmt) {
print "\t\t<font face ='Arial' size='1' color='#008000' > Page ".$p. ' of
'.ceil($_maxelmt/$MAXHIT). '</font>'.
"\n";
}
} /*if ($_maxelmt> $MAXHIT)
} /*end lse if(!$MAXHIT)*/
?>


/********************************************************************************
Example of use in results.php3: 9 hits maximum, in a 3*3 table

Note: the colspans of <td> may not be correct as I adapted this example
from another presentation
********************************************************************************/
<?

/*place here your code to query MySQL database...*/

/*get results*/
if(strcmp($result, ''))
$number=mysql_numrows($result);
else
$number=0;

/*maximum number of hits*/
$MAXHIT= 9;

/*if more than MAXHIT results are found, split the results into several pages*/
$i=$MAXHIT*$p;

/* --> $p is initialized to 0 if results.php3 is 1st called, but then it gets its value
from split.php3!*/

print " <table border='0'>\n";
print " <tr>\n";
print " <td>\n";
/*remind query or show a sorry message if no result was found:*/
print "Your query: $qry.\n";
print " </td>\n";
print " </tr>\n";

if($number) {
print "\n\t <tr>\n";
print "\t <td'>\n";
if($number>1) {
/*split header*/
$plural= 's';
$pluralbe= 'were';
}
else {
$plural= '';
$pluralbe= 'was';
}

/*displays details about results*/

print "\t\t$number result$plural $pluralbe found for this query\n";
print "\t\t<hr size='1'>\n"; print "\t </td>\n"; print "\t </tr>\n";
print "\t <tr>\n";
print "\t <td>\n";

/*category of result page to show when returning from split module*/
$cat= "[optional parameters]";
$urlinfo= "p=$p&_maxelmt=$number&MAXHIT=$MAXHIT&cat=".$cat;

/*calling split module*/
"http://[your path]/split.php3?$urlinfo&res=1";

print "\t <tr>\n";
print "\t <td>\n";

print "\t\t<table border='0' cellspacing='1' cellpadding='1'>\n";

/*default recordset scanning is 0 to MAXHIT-1 (p=1)*/
$i=$MAXHIT*($p-1);

while ($i<$MAXHIT*$p && $i < $number) {
$mVar1=mysql_result($result,$i, "Var1");
$mVar2=mysql_result($result,$i, "Var2");
/*etc...*/

$index=$i+1;

/*format table*/
if (!($i % 3)) {
print "\t\t <tr>\n";
}
$mName= "$mVar1/$mVar2.html"; /*for instance...*/

print "\t\t <td>\n\t\t\t<a href='$mName'>\n";
print "</a>\n\t\t </td>\n";

if (($i % 3) == 2) {
print "\t\t </tr>\n";
}
/*next record*/
$i++;
} /*end while*/

/*if table didn't end in a full row, append end of row*/
if ($i % 3) {
print "\t\t </tr>\n";
}
print "\t\t</table>\n";

print "\t </td>\n";
print "\t </tr>\n";
} /*end if $number*/

else {
print "\t <tr>\n";
print "\t <td>\n";
/*sorry message*/
print "\t\tSorry, no result was found in the database\n";
print "\t </td>\n";
print "\t </tr>\n";
}

print " </table>\n";
?>



Message of the Day - Random Message (Needs MySQL!)
Categories : Databases, HTML and PHP, PHP, MySQL
A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL
Automatically printing the contents of an sql table in MySQL.
Categories : MySQL, PHP, HTML and PHP, Databases
Pull Down Surfing - Surf on Change
Categories : Java Script, MySQL, HTML and PHP, PHP, Databases
Dynamically generated pop-ups (Select items)
Categories : PHP, HTML and PHP, MySQL, Databases
Alternating background color for HTML table rows
Categories : PHP, Databases, MySQL, HTML and PHP
Functions for loading images into a MySQL database and displaying them.
Categories : Graphics, HTML and PHP, MySQL, PHP, Databases
Creating thumbnails from MySQL Blobs online
Categories : PHP, MySQL, Graphics, HTML and PHP, Databases
Editing the virtusertable and sendmail.cw via PHP3.0 and Mysql
Categories : MySQL, HTML and PHP, PHP, Databases
This function will populate the options in a drop down HTML select list in a form from a database query.
Categories : MySQL, General SQL, PHP, HTML and PHP, Databases
How can i Preload a 'SELECT MULTIPLE'?
Categories : HTML and PHP, PHP, MySQL, Databases
Record Set Paging with PHP (RSP)
Categories : PHP, MySQL, Navigation, Databases, HTML and PHP
dynamic table columns
Categories : PHP, HTML and PHP, Arrays, Databases, MySQL
Paginating the mySQL data
Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP
PHP and MySQL scripting for Muyltiple CheckBoxes
Categories : HTML and PHP, MySQL, Databases, PHP
 Daniel Geiger wrote :377
This is pretty cool.