Domain Discussion Board

Go Back   Domain Discussion Board > Web Hosting & Web Design > Scripts

 
Reply
 
LinkBack Thread Tools Display Modes
Php item list/paging script
Old
  (#1 (permalink))
godkillah
Junior Member
godkillah is on a distinguished road
 
Status: Offline
Posts: 25
Points: 50.4
Bank: 0.0
Total Points: 50.4
Donate
Join Date: Sep 2007
Rep Power: 0
Php item list/paging script - 07-13-2008, 12:11 PM

this is a basic script to load content from rows of out of a database with paging system
it is mainly meant to teach and show you how to do such a thing
enjoy the script

PHP Code:
<?php 
/*by Godkillah 
http://www.phantom-designs.net 
http://www.vbdeals.com*/ 

define("MyHost",'localhost'); 
define("MyDB",'MyDatabase'); 
define("Username",'myusername'); 
define("Password",'mypassword'); 
define("TABLEOFDOOM",'MyTable'); 
define("DoomedResults",25); 

//No further edits required 
$connect mysql_connect(DBHOST,DBUSER,DBPASS) or die('<script type="text/javascript">ar=["block","none"];i=0;function showdetails(){document.getElementById("errordetails").style.display=ar[i]; if(i>0){ i--; }else{ i++;}}</script>Failed to connect to host,<Br>for more details click <a href="javascript:void(0)" onclick="showdetails()">here</a><div id="errordetails" style="display:none"><i>'.mysql_error().'</i></div>'); 
if(!
$connect){ 
exit(); 

$connect2=mysql_select_db(DBNAME$connect) or die('<script type="text/javascript">ar=["block","none"];i=0;function showdetails(){document.getElementById("errordetails").style.display=ar[i]; if(i>0){ i--; }else{ i++;}}</script>Failed to connect to database,<Br>for more details click <a href="javascript:void(0)" onclick="showdetails()">here</a><div id="errordetails" style="display:none"><i>'.mysql_error().'</i></div>'); 
if(!
$connect2){ 
exit(); 

//from here the paging starts 
$resultsperpage=DoomedResults
$curpage=1
if(isset(
$_GET['page'])){ 
$curpage=$_GET['page']; 

$offset=($curpage-1)*$resultsperpage
$result=mysql_query("SELECT * FROM ".TABLEOFDOOM." LIMIT ".$offset.", ".$resultsperpage.";"); 
$r mysql_query("SELECT * FROM ".TABLEOFDOOM.";"); 
$rows=mysql_num_rows($r); 
$pages1=$rows/$resultsperpage
$pages=round($pages1); 
if(
$pages1>$pages){ 
$pages++; 

$listo='<b>Pages: </b>'
if(
$curpage!=1){ 
$listo.=' [<a href="index.php?action=list&page='.($curpage-1).'">Previous</a>]'

for(
$i=1;$i<=$pages;$i++){ 
if(
$curpage==$i){ 
$listo.=' <b>['.$curpage.']</b>'
}else{ 
$listo.=' [<a href="index.php?action=list&page='.$i.'">'.$i.'</a>]'
}} 
if(
$curpage!=$pages && $pages!=0){ 
$listo.=' [<a href="index.php?action=list&page='.($curpage+1).'">Next</a>]'

$addstuff=''
if(
$pages==0){ 
$listo.=' <b>[1]</b>'
$pages++; 
$addstuff='There is currently no list!'

$listo.=' ('.$pages.' total)'
$conts='' 
while($row=mysql_fetch_array($result)){ 
$conts.='<div>'.$row['mylistitem'].'</div>'

$conts.=$addstuff
//time to write both the page browsing links and the listitems 
echo $listo
echo 
$conts
echo 
$listo
//$listo is the page links, $conts is the loaded list items 
?>
   
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 0.1
Points Per Thread: 15.0
Points Per Reply: 5.0


Similar Threads
Thread Thread Starter Forum Replies Last Post
FREE CGI Hosting blue-sky Wonderful Websites 22 04-27-2008 06:12 AM
Free php web hosting...Part 1 blue-sky Hosting Providers 24 12-22-2007 01:28 AM
List of Great Scripts For Sale keemuph ddPoints Exchange 0 09-29-2007 06:20 AM


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 ©2007, Crawlability, Inc.