[liphp] RE: Next Page Help - Perfecto!!

Troy Thomas [email protected]
18 Oct 2003 00:11:45 -0400


I got it working, THANKS Sasha for pointing me in the right direction.

After I made the changes you suggested I got some other errors which
help me find and figure out the last parts of the puzzle.

Here is the code:

<?
session_start();
$tempcat_name = $_GET['cat_name'];
$cat_id = $_GET['cat_id'];
$tempcat_name = $_SESSION['tempcat_name'];
$page = $_GET['page'];
$limit = 10;

$db_name ="alpha";
$connection = mysql_connect("*****","******","*****") or
die(mysql_error());
$db = mysql_select_db($db_name,$connection) or die(mysql_error());

$query_count = "SELECT userid, username, company, cat_name, pro_id,
pro_name, pro_desc FROM user_table, category, products WHERE
user_table.userid = products.user_id AND products.cat_id =
category.cat_id AND category.cat_id = $cat_id";

$result_count = mysql_query($query_count);    
    // Pulls what we want from the database
$totalrows = mysql_num_rows($result_count); 

    if(empty($page)){
        $page = 1; 
    }

$limitvalue = ($page * $limit - ($limit));

$query  = "SELECT userid, username, company, cat_name, pro_id, pro_name,
pro_desc FROM user_table, category, products WHERE user_table.userid =
products.user_id AND products.cat_id = category.cat_id AND
category.cat_id = $cat_id limit $limitvalue, $limit";      
 
$result = mysql_query($query) or die("Error: " . mysql_error());
	
	   
    if(mysql_num_rows($result) == 0){
        $option_block .= ("<tr><td height=145  align=center
colspan=2><P><em>Sorry! No results under this category yet check back
soon. Thank you.</em></p></td></tr>");
    }
	
	   $bgcolor = "#efefef";	
	   
	while($row3 = mysql_fetch_array($result)){
        
        // Start The Background Check
        if($bgcolor == "#e4e4e4"){
		
            $bgcolor = "#efefef";
			
        } else {
		
            $bgcolor = "#e4e4e4";
        }    
	                                                                
		$company = $row3['company'];
		$user_id = $row3['user_id'];
		$cat_id2 = $row3['cat_id'];
		$cat_name = $row3['cat_name'];
		$pro_id = $row3['pro_id'];
		$pro_name = $row3['pro_name'];
		$pro_desc = $row3['pro_desc'];
        $cutpro_desc = substr($pro_desc,0,75);
	
	$option_block .= "<tr bgcolor=$bgcolor><td height=45
valign=top><b>Company: </b>$company<br><b>Product Name: </b><a
href=\"viewproduct.php?pro_id=$pro_id\">$pro_name</a> - $cutpro_desc
...</td><td width=5 ><input type=\"checkbox\"></td></tr>";

	}
	

	
	
    if($page != 1){
        $pageprev = $page-1;
        
         $pagecount = ("<a
href=\"$_SERVER[PHP_SELF]?page=$pageprev&cat_name=$cat_name&cat_id=$cat_id\">< PREV</a>&nbsp;"); 
		 
    } else {
	
        $pagecount = ("< PREV&nbsp;");
        
		}
    $numofpages = ($totalrows / $limit);
    
    for($i = 1; $i <= $numofpages; $i++) {
    
        if($i == $page){
		
            $pagecount .= ($i."&nbsp;");
			
        } else { 
		
           $pagecount .= ("[<a
href=\"$_SERVER[PHP_SELF]?page=$i&cat_name=$cat_name&cat_id=$cat_id\">$i</a>]&nbsp;");
		   
        }
 
    }

    if(($totalrows % $limit) != 0) {
     
        if($i == $page){
		
            $pagecount .= ($i."&nbsp;");
			
        } else {
		
            $pagecount .= ("[<a
href=\"$_SERVER[PHP_SELF]?page=$i&cat_name=$cat_name&cat_id=$cat_id\">$i</a>]&nbsp;");
			
        }
    } 

    if(($totalrows - ($limit * $page)) >= 0){
    
        $pagenext = $page +1;
         
        $pagecount .= ("<a
href=\"$_SERVER[PHP_SELF]?page=$pagenext&cat_name=$cat_name&cat_id=$cat_id\">NEXT ></a>");
    
    } else {
	
        $pagecount .= ("NEXT >");
    }
	mysql_free_result($result);
	$option_block .= "<tr><td colspan=\"2\">&nbsp;</td></tr><tr><td
align=\"center\" height=\"20\" colspan=\"2\">$pagecount</td></tr>";
?>

I hope this can help someone else also.

Thanks Much,
troinfo
-- 

"Which brings us at last to the moment of truth

where in the fundamental flaw is ultimately expressed

and the anomaly revealed as both the beginning and end."