Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

Php Programming Code Examples

Php > Site Navigation Code Examples

Page Scroller ver 3

Page Scroller ver 3 <? #database configuration $db_user = "root"; $db_pass = "pass"; $db_name = "phpMember"; $db_host = "localhost"; mysql_pconnect($db_host, $db_user, $db_pass) or die("Unable to connect to SQL server"); mysql_select_db($db_name) or die("Unable to select database"); #page scroller configuration $script="scroller3.php3"; $offset+=0; $item_perpage= 2; #----change this to define how many item per page $prev= $offset-$item_perpage; $next= $offset+$item_perpage; #query configuration $tbl_search = "country"; $field="name "; $query="SELECT $field FROM $tbl_search WHERE $field LIKE '%$keyword%' LIMIT $offset, $item_perpage"; $querytotal="SELECT count(*) FROM $tbl_search WHERE $field LIKE '%$keyword%'"; $total=mysql_fetch_row(mysql_query($querytotal)); #----modify the where clause to fit your query need #page map $pages = (int) ($total[0] / $item_perpage); if ($total[0] % $item_perpage) {$pages++;} for ($a=1;$a<=$pages;$a++) { $map[$a] =" <a href=\"$script?offset=$offset2&keyword=$keyword\">$a</a> "; $offset2+=$item_perpage; } $pagemap=implode("|", $map); #prev next condition if ($prev < 0) {$prev="";} else {$prev="<a href=\"$script?offset=$prev&keyword=$keyword\"><< PREV</a>";} if ($total[0] > $next) {$next="<a href=\"$script?offset=$next&keyword=$keyword\">NEXT >></a>";} else {$next="";} ?> <html> <head><title>CyberGL Page Scroller</title></head> <body> Query: <?echo $query;?> <hr> <b><?echo $offset+1?> to <?echo $offset+$item_perpage?> of <?echo $total[0]?></b> <p> <? #-query process $data=mysql_query($query); $no=1; while ($result=mysql_fetch_array($data)) { ?> NO: <?echo $no+$offset;?>. <?echo $result[name]?><p> <? $no++; } #page scroller ?> <table width="100%" cellpadding=0 cellspacing=0 border=0> <tr> <td nowrap><?echo $prev?></td> <td width="100%" align=center><?echo $pagemap?></td> <td align=right nowrap><?echo $next?></td> </tr> </table> </body> </html>