Pager

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Redghost
Forum Newbie
Posts: 5
Joined: Thu Dec 30, 2004 3:52 am
Location: Lithuania

Pager

Post by Redghost »

I have a problem with pager. This is here:

Code: Select all

<?php
class Pager 
  { 
  
   function findStart($limit) 
    { 
     if ((!isset($_GETї'page'])) || ($_GETї'page'] == "1")) 
      { 
       $start = 0; 
       $_GETї'page'] = 1; 
      } 
     else 
      { 
       $start = ($_GETї'page']-1) * $limit; 
      } 

     return $start; 
    } 
 
  
   function findPages($count, $limit) 
    { 
     $pages = (($count % $limit) == 0) ? $count / $limit : floor($count / $limit) + 1; 

     return $pages; 
    } 
  
    
   function nextPrev($curpage, $pages) 
    { 
     $next_prev  = ""; 

     if (($curpage-1) <= 0) 
      { 
       $next_prev .= "Previous"; 
      } 
     else 
      { 
      	if(!isset($_GETї'id']))
      	{
       $next_prev .= "<a href="".$_SERVERї'PHP_SELF']."?page=".($curpage-1)."">Previous</a>"; 
      	}
      	else 
      	{
      		 $next_prev .= "<a href="".$_SERVERї'PHP_SELF']."&page=".($curpage-1)."">Previous</a>"; 
      	}
      } 

     $next_prev .= " | "; 

     if (($curpage+1) > $pages) 
      { 
       $next_prev .= "Next"; 
      } 
     else 
      { 
       if(!isset($_GETї'id']))
      	{
       $next_prev .= "<a href="".$_SERVERї'PHP_SELF']."?page=".($curpage+1)."">Next</a>"; 
      	}
      	else 
      	{
      		 $next_prev .= "<a href="".$_SERVERї'PHP_SELF']."&page=".($curpage+1)."">Next</a>"; 
      	}
      } 

     return $next_prev; 
    } 
  } 


?>

Code: Select all

<?php
require("class.pager.php");
$db_prisijungimas = mysql_connect("localhost", "username", "pass") 
					or die("Negalime prisijungti prie duombazes" . mysql_error());
mysql_select_db ("stebuklas", $db_prisijungimas) 
				or die("Nerandu duombazes" . mysql_error());
$kategorijos = "SELECT id, name FROM logo_categories;";
$query_results = mysql_query ($kategorijos, $db_prisijungimas)
$p = new Pager;
$limit = 20;
$start = $p->findStart($limit);
$count = mysql_num_rows(mysql_query("SELECT id,cat_id FROM logo"));
$pages = $p->findPages($count, $limit);
	 
			
print"<center>";
while ($row = mysql_fetch_object ($query_results))
{
print("<a href="$PHP_SELF?id=" . $row -> id . " " >" . $row -> name ."</a>"); 
print(" | ");
}
print("</center>");
$i = 1;
print("</br></br></br>");
if(!isset($_GETї'id']))
{
$logo = "SELECT id,cat_id  FROM logo LIMIT $start,$limit ;";
$logo_results = mysql_query ($logo, $db_prisijungimas) or die(mysql_error());				
while ($rows = mysql_fetch_object($logo_results))
{
print ("<td width="120" valign="middle">");
print ("<img src="mysite.com/". $rows -> id .".gif "></BR>");
print ("<font size="1">LOGO ". $rows -> id ."54</font>");
print ("</td>");
print ("<td width="15" valign="top"><td>");
$i+=1; 
if ($i==5) 
{ 
$i=1; 
print ("</tr>"); 
print ("<tr><td height = "25" valign="top"></td></tr>");
print ("<tr>");
}
} 
print("<tr><td valign="top">");
$next_prev = $p->nextPrev($_GETї'page'], $pages); 
print($next_prev);
print("<td></tr>");
}
else
{
 $logo = "SELECT id,cat_id  FROM logo  WHERE cat_id = ". $_GETї'id'] . "LIMIT $start,$limit ;";
$logo_results = mysql_query ($logo, $db_prisijungimas) or die(mysql_error());
while ($rows = mysql_fetch_object($logo_results))
{
print ("<td width="120" valign="middle">");
print ("<img src="mysite.com/". $rows -> id .".gif "></BR>");
print ("<font size="1">LOGO ". $rows -> id ."54</font>");
print ("</td>");
print ("<td width="15" valign="top"><td>");
$i+=1; 
if ($i==5) 
{ 
$i=1; 
print ("</tr>"); 
print ("<tr><td height = "25" valign="top"></td></tr>");
print ("<tr>");
} 
}
print("<tr><td valign="top">");
$next_prev = $p->nextPrev($_GETї'page'], $pages); 
print($next_prev);
print("<td></tr>");
}

?>
When id is not set, then everything ok, but when id is set then i get an error:

Code: Select all

You have an error in your SQL syntax near '0,20 ' at line 1
What's wrong? People please help me.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

line 52 should be:

Code: Select all

$logo = "SELECT id,cat_id  FROM logo  WHERE cat_id = ". $_GET['id'] . " LIMIT $start,$limit ;";
Redghost
Forum Newbie
Posts: 5
Joined: Thu Dec 30, 2004 3:52 am
Location: Lithuania

Post by Redghost »

Thanks
Post Reply