code,keep,from,having,rewrite,codeas,well,pre
Quick Search for:  in language:    
code,keep,from,having,rewrite,codeas,well,pre
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
PHP Stats

 Code: 74,754 lines
 Jobs: 12 postings

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for PHP.
Smart Image Navigator
By Brian Di Croce on 10/27


Click here to see a screenshot of this code!Form security verification
By Christian Mallette on 10/26

(Screen Shot)

Click here to see a screenshot of this code!Guestbook
By Nightmare on 10/25

(Screen Shot)

Shout! Box
By Nightmare on 10/23


SERVER-TO-SERVE R site (or single dir) transfer
By Raffaele Marranzini on 10/22


Site IP Logger - Watch who comes to your site!
By KRaZY-DeSiGN on 10/21


IP Banner - Block unwanted people from your site!
By KRaZY-DeSiGN on 10/20


PWGen
By Flinn Mueller on 10/19


URHere
By Flinn Mueller on 10/19


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

previous next(working)updated already

Print
Email
 
VB icon
Submitted on: 9/14/2002 4:13:45 AM
By: cpsim  
Level: Intermediate
User Rating: Unrated
Compatibility:PHP 3.0, PHP 4.0

Users have accessed this code 549 times.
 
(About the author)
 
     i set this code up to keep from having to rewrite sql code. as well as a having previous next on my search results. this code could be expanded on for many other things. this should cut your code way down. on repeating mysql statements. this is just my version for previous next. i have not found any bugs in it as of yet except now and then there may be a blank page at the end of results. of your max results is only 1 then the last page will be blank. i have only tested to 25 and else it seems to work fine. let me know of any bugs you see in it and find other than what i stated. i have fixed the blank page at the end on some listing by using $pages=ceil($num_result1/$max); rather than using number_format();this should be exceptional now.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    //**************************************
    //     
    // Name: previous next(working)updated a
    //     lready
    // Description:i set this code up to kee
    //     p from having to rewrite sql code.
    as well as a having previous next on my search results. this code
    could be expanded on for many other things.
    this should cut your code way down. on repeating mysql statements.
    this is just my version for previous next.
    i have not found any bugs in it as of yet except now and then there
    may be a blank page at the end of results.
    of your max results is only 1 then the last page will be blank.
    i have only tested to 25 and else it seems to work fine.
    let me know of any bugs you see in it and find other than what i stated.
    i have fixed the blank page at the end on some listing by using $pages=ceil($num_result1/$max);
    rather than using number_format();this should be exceptional now.
    // By: cpsim
    //
    // Inputs:see code
    //
    //This code is copyrighted and has    // limited warranties.Please see http://
    //     www.Planet-Source-Code.com/xq/ASP/txtCod
    //     eId.742/lngWId.8/qx/vb/scripts/ShowCode.
    //     htm    //for details.    //**************************************
    //     
    
    <?php
    //i set this code up to keep from having
    //     to rewrite sql code.
    //as well as a having previous next on m
    //     y search results. this code
    //could be expanded on for many other th
    //     ings.
    //this should cut your code way down. on
    //     repeating mysql statements.
    //this is just my version for previous n
    //     ext.
    //i have not found any bugs in it as of 
    //     yet except now and then there
    //may be a blank page at the end of resu
    //     lts.
    //of your max results is only 1 then the
    //     last page will be blank.
    //i have only tested to 25 and else it s
    //     eems to work fine.
    //let me know of any bugs you see in it 
    //     and find other than what i 
    //stated. will have a sourcecode section
    //     at my site soon.
    //if you expand on this code i would lik
    //     e a copy of it.
    //cuddlenlv@yahoo.com
    //http://nb-ware.com
    //must classify your max results
    $max=10;
    $page1=$page;
    $pagea=$page*$max;
    //must classify $criteria and place
    $critteria1="LIMIT $pagea,$max";
    $place="products";
    $action=getenv("QUERY_STRING");
    If ($action==""){
    $page=0;
    $max=2;
    }
    //this shows the statistics of the resul
    //     ts
    	$st=connects();
    	$resa=selectdata($place,'');
    	$numres1=numres($resa);
    	closea($st);
    	echo $page1*$max+1; 
    	echo " - ";
    	if ($max*$page2 > $numres1){
    		echo $numres1;
    	}
    	if ($max*$page2 < $numres1){
    		echo $max*$page2;
    	}
    	echo " Of ";
    	echo $numres1;
    	echo " Results <br><hr>";
    //the small bit of code to work it	
    	$st=connects();	
    	$resa=selectdata($place,$critteria1);
    	$numres=numres($resa);
    	for ($is = 0;$is <= $numres-1;$is++) {
    	$line = mysql_fetch_array($resa);
    	print "$line[name]<br>";
    	}
    	closea($st);
    	$st=connects();
    	getthedata($place,'',$max,$page,$page1,$PHP_SELF);
    	closea($st);
    //end of small bit of code
    //the rest can reside in another file as
    //     long as it is included some where in the
    //     page.
    //funtions
    function connects(){
    //connects to mysql database
    	//here you need the server'localhost' your 'username' and 'password'
    	$connection = mysql_connect('servername or address', 'username', 'password') or die("Connection error!");
    	$db1="dbase";
    	mysql_select_db($db1, $connection);
    	return($connection);
    }
    function selectdata($place,$critteria1){
    //selects database from database
    	$query = "SELECT * FROM $place $critteria1";
    	$result = mysql_query($query) or die("ERROR");
    	return($result);
    }
    function numres($result){
    //returns number result
    	$num_result = mysql_num_rows($result);
    	return($num_result);
    }
    function closea($st){
    //closes mysql database
    	mysql_close($st);
    }
    function getthedata($place,$criteria,$max,$page,$page1,$PHP_SELF){	
    //gets complete data
    	$query = "SELECT * FROM $place $criteria";
    	$result = mysql_query($query) or die("ERROR");
    	$num_result1 = mysql_num_rows($result);
    	$pages=ceil($num_result1/$max);
    //previous stuff
    	if ($page>0){
    		echo "<a href='$PHP_SELF?page=";
    		echo $page-1;
    		echo "'><< Prev</a> ";
    	}else{
    	}
    //current stuff
    	for ($it=1;$it <= $pages;$it++){
    		if ($it==$page1+1){
    			echo $it;
    			echo " ";
    		}else{
    			print "<a href='$PHP_SELF?page=";
    			print $it-1;
    			print "'>$it</a> ";
    		}
    	}
    //next stuff
    	if ($page<$pages-1){
    		echo "<a href='$PHP_SELF?page=";
    		echo $page+1;
    		echo "'>Next >></a> ";			
    	}else{
    	}
    }
    ?>

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
9/14/2002 5:15:37 AM:cpsim
now has the statistics at the head.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | PHP Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.