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 2

Page Scroller ver 2 <? #---------------------------------------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="scroller2.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 #---------------------------------------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>Page Scroller</title></head> <body> Query: <?echo $query;?> <hr> <b><?echo $offset?> 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><?echo $prev?></td> <td align=right><?echo $next?></td> </tr> </table> </body> </html>