FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Pagination and Tables





danway60
Hey.
I've been able to construct a simple PHP Pagination page using a tutorial from PHP Freaks. The thing is I'm wanting to use the pagination for my website, however, I need to arrange the data into a table so I can have 3 columns and 10 rows. An example of what I want is: http://gamecity.frihost.net/Games/Tower%20Defence/
and currently I am hard coding all of the data on my website and I am wanting to convert it to data stored in a database as it would be a lot easier to maintain and add new games.

Is this possible?

Thanks, Dan.
Star Wars Fanatic
danway60 wrote:
Hey.
I've been able to construct a simple PHP Pagination page using a tutorial from PHP Freaks. The thing is I'm wanting to use the pagination for my website, however, I need to arrange the data into a table so I can have 3 columns and 10 rows. An example of what I want is: http://gamecity.frihost.net/Games/Tower%20Defence/
and currently I am hard coding all of the data on my website and I am wanting to convert it to data stored in a database as it would be a lot easier to maintain and add new games.

Is this possible?

Thanks, Dan.


For sure, you can do it no problem. You will need to know how to work with databases, and php, but it can be done quite easily.
danway60
Do you know any good tutorials on how to do this? or are you able to give me an example please?

Thanks, Dan.
kv
Here is a online code generator which generates code in form of a set of php files. You can look at the code, use the files as is or modify according to your requirement or use the code in your files.

http://www.turningturnip.co.uk/free-mysql-php-generator/index.php
urtrivedi
Code:

function linkstr($reccount,$rowperpage,$totalpages)
   {
   

      $showlinks=4; //how many links to show 1|2|3|4
      $frompage=$_POST['page'];
      $topage=$_POST['page']+$showlinks;
      if ($topage>$totalpages)
         $topage=$totalpages;
       
      if ($totalpages>$showlinks )
      {
         if (($topage-$frompage)<$showlinks)
            $frompage=$topage-$showlinks;
      }
      else
      {
         $frompage=1;
         $topage=$totalpages;
      }
       
      $prevpageno=$frompage-1;
      $nextpageno=$topage+1;
      if($nextpageno>$totalpages)
         $nextpageno=$totalpages;
       
      $linkstr=   "";
      $imgno="";
      $prevchar="";//chr(171);
      $nextchar="";//chr(187);

      if ($totalpages>1)
      {
           
          if ($frompage>1)
            $linkstr.= "\n<a class='text12' href='javascript:link_click(1);' title='First'><img src='../images/first{$imgno}.gif' border=0 >{$prevchar}{$prevchar}</a> | ";   
          if ($frompage>2)             
            $linkstr.=  "\n<a  class='text12' href='javascript:link_click({$prevpageno});' title='Previous'><img src='../images/previous{$imgno}.gif' border=0 >{$prevchar}</a> | ";   
         
         //for loop
         for ($i=$frompage;$i<=$topage;$i++)
         {
             if ($_POST['page']!=$i)
               $linkstr.= "\n<a  class='text12' href='javascript:link_click({$i});'><u><strong>";
            $linkstr.= $i;
             if ($_POST['page']!=$i)             
               $linkstr.= "</strong></u></a>";   
            if ($i<$topage)       
               $linkstr.= " | ";
         }
         //end for
         if ($topage<$totalpages-1)
            $linkstr.=   "\n | <a  class='text12' valign='bottom' href='javascript:link_click({$nextpageno});' title='Next'><img src='../images/next{$imgno}.gif' border=0>{$nextchar}</a>";
         if ($topage<$totalpages)
            $linkstr.=   "\n | <a  class='text12' href='javascript:link_click({$totalpages});' title='Last'><img src='../images/last{$imgno}.gif' border=0>{$nextchar}{$nextchar}</a>";   
             
      }
       
      return $linkstr;
   }

   $query="SELECT * FROM YOU TABLE WHERE YOUR CONDTIONS ";
   
   $reccount=execute query ("SELECT COUNT(*) FROM (".$query.") A ",$connection); // to find total no of records
   
   $rowperpage=10;
   
   $totalpages=ceil($reccount/$rowperpage);
   
   if (!isvalueset($_POST['page']))
      $_POST['page']=1;
       
   $fromrecord=((($_POST['page']-1)*$rowperpage)+1);
   $torecord=$_POST['page']*$rowperpage;
   
   $fromrecord=$fromrecord-1;
   $torecord=$rowperpage;


   $query=$query."  LIMIT {$fromrecord},{$torecord} ";


   //execute your query here;
   
?>
<html>
<head>
<script language='javscript'>
   function link_click(pageno)
   {
       document.frmsearch.target='_self';
       document.frmsearch.page.value=pageno;
      document.frmsearch.submit();
   }
</script>
</head>
<body>
<?php   
   print "\n<table width=100% border=1 cellspacing=0 cellpadding=0>";
   //show your records here
   print "\n</table>";   


   //display page navigaation
   print "\n<table width=100% border=1 cellspacing=0 cellpadding=0>";
   print "\n<tr>";
   

   if ($reccount>0)
   {
      print "\n<td align=left width=25%><b>Total Record(s): {$reccount}</b></td>";
      if ($showdesign)
      {       
         print "\n<td align=center width=50%>".linkstr($reccount,$rowperpage,$totalpages)." &nbsp;</td>";
         print "\n<td align=right width=25%><b>Page {$_POST['page']} of {$totalpages}</b> &nbsp;</td>";
      }
   }
   else
   {
      print "\n<td align=center width=100%><b><br>No Record found.<br></b></td>";
   }
   print "\n</tr>";
   print "\n</table>";   
   
?>
<form name=frmsearch id=frmsearch method=post>
<input  type=hidden name=page id=page value=1>
</form>
<body>
</html>

danway60
Parse error: syntax error, unexpected T_STRING in /bjw.php on line 66

Why am I getting this?


its from this:
$reccount=execute query ("SELECT COUNT(*) FROM (".$query.") A ",$connection); // to find total no of records


Dan.
rvec
that's a bad way to do this. and it's because of the "execute query" part. I think you should do mysql_query() there.
danway60
I think you missed out a function:

isvalueset()

Fatal error: Call to undefined function isvalueset() in /bjw.php on line 72

Can I have the code for that function Razz

Dan.
Star Wars Fanatic
danway60 wrote:
I think you missed out a function:

isvalueset()

Fatal error: Call to undefined function isvalueset() in /bjw.php on line 72

Can I have the code for that function Razz

Dan.


Just change "sivalueset" to "isset". It's a built in php function that has the same functionality that I think that function has. You also might want to check if the value is numeric.
pashmina
interesting website.
you could you the paginating class which is available from nettuts.com
Related topics
PHP without mySQL
How To : Improve Your PHP Programming
I cant install php chat tables nor set up diffrent subdomain
Tutorial: PHP Installed Modules Dynamic Reference Tool
[PhP] News Posting Tutorial (code, actually ^^')
PHP DB Error: syntax error
PHP tables
PHP Question
PHP what is it actually?
What happened on my tables?
A very good PHP MySQL Tutorial
PHP Script needed
site check
PHP Pagination?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.