Old 05-23-2005   #1 (permalink)
Registered User
 
Join Date: May 2005
Posts: 2

Help needed with PHP: Pagination in a tut system

Hey, i have made a tutorial system (Which is copyright and you are not allowed to use it as of yet, as i havn't released it... i may do in the near futre though.) But, now i have loads of tutorials being put on my web site, they are getting so far down the page, and I was wandering if someone could figure out a way to add a pagination to the pages, when you have clicked on a category to go to.

Here is the tutorial system:

Code:
<?php
include ("dbconnect.php");

switch ($view ) { // simple switch function
default: //states wat will show up if view doesn't = nething
$sql_query = "SELECT * FROM tutorials";
$result = mysql_query($sql_query);
$rows = mysql_num_rows($result);
echo "<center>There are currently <strong>($rows)</strong> tutorials all together<BR><BR></center>";
echo "<strong>Select type:</strong><br>";
echo "<a href=\"?nitr0x=tutorials/tutorials&view=all&sec=photoshop\">Photoshop</a> <br><a href=\"?nitr0x=tutorials/tutorials&view=all&sec=php\">PHP</a><br><a href=\"?nitr0x=tutorials/tutorials&view=all&sec=html\">HTML</a><br><a href=\"?nitr0x=tutorials/tutorials&view=all&sec=submitted\">Submitted</a>";
break; 

case "all":
$sec = $_GET["sec"];
$get = "SELECT * FROM `tutorials` WHERE section='$sec'";
$go = mysql_query($get);
 
while ($adam = mysql_fetch_array($go)) {


$color_1 = "#921414";
$color_2 = "#CC1C1C";
static $color;
if ($color == $color_1) {
$color = $color_2;
}
else {
$color = $color_1;
/// $color
}

/////////// HTML BIT GOES HERE
?>


<table width="100%" bgcolor="<? echo "$color"; ?>" border="0" cellspacing="0" cellpadding="0" style="border-style: dashed; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1">
  <tr>
    <td><strong><? echo "$adam[title]"; ?></strong></td>
  </tr>
  <tr>
    <td>Submitted On: <? echo "$adam[date]"; ?></td>
  </tr>
  <tr>
    <td>Description: <? echo "$adam[description]"; ?></td>
  </tr>
  <tr>
    <td>Submitted By: <? echo "$adam[user]"; ?></td>
  </tr>
  <tr>
    <td><a href="?x=tutorials/tutorials&view=view&id=<? echo "$adam[ID]"; ?>">View Tutorial</a></td>
  </tr>
</table>
<br>

<?
//////////// END HTML PART
}
break; case "view":
$id = $_GET["id"]; // Sets the variable from the url - grabs the id # from url
$get = "SELECT * FROM `tutorials` WHERE ID='$id'";  // sql statement
$go = mysql_query($get); // retrieve the sql statment
while ($adam = mysql_fetch_array($go)) { // do this until finished
////////////// START HTML PARTS fOR VIEWING
?>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="right"><a href="?x=tutorials/tutorials"><strong>Tutorials</strong></a> 
        <strong>::</strong> <strong><? echo "<a href=\"?x=tutorials/tutorials&view=all&sec=$adam[section]\">$adam[section]</a>";
 ?></strong></div></td>
  </tr>
  <tr>
    <td><div align="center"><strong>:: <? echo "$adam[title]"; ?> ::</strong></div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="left"><? echo "$adam[message]"; ?></div></td>
  </tr>
  <tr>
  <Td>
  <div align="right"><strong>Written by : <? echo "$adam[user]"; ?></strong></div>
  </Td>
  </tr>
</table>
<?
///////// END HTML PARTS FOR VIEWING OF TUTORIAL
}
}
?>
I'm guessing the pageination would be where the:

Code:
case "all":
$sec = $_GET["sec"];
$get = "SELECT * FROM `tutorials` WHERE section='$sec'";
$go = mysql_query($get);
 
while ($adam = mysql_fetch_array($go)) {


$color_1 = "#921414";
$color_2 = "#CC1C1C";
static $color;
if ($color == $color_1) {
$color = $color_2;
}
else {
$color = $color_1;
/// $color
}

/////////// HTML BIT GOES HERE
?>


<table width="100%" bgcolor="<? echo "$color"; ?>" border="0" cellspacing="0" cellpadding="0" style="border-style: dashed; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1">
  <tr>
    <td><strong><? echo "$adam[title]"; ?></strong></td>
  </tr>
  <tr>
    <td>Submitted On: <? echo "$adam[date]"; ?></td>
  </tr>
  <tr>
    <td>Description: <? echo "$adam[description]"; ?></td>
  </tr>
  <tr>
    <td>Submitted By: <? echo "$adam[user]"; ?></td>
  </tr>
  <tr>
    <td><a href="?x=tutorials/tutorials&view=view&id=<? echo "$adam[ID]"; ?>">View Tutorial</a></td>
  </tr>
</table>
is... but i'm not too sure, if you can figure this out it would be so much appreciated, and you would get a mention on the site... and on the tutorial system if it gets released.
nitr0x is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 05-24-2005   #2 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
You meant u need a pagination tut rite,try search this category (HTML / PHP / ASP / JS),i had posted a tut like that some where here,but its a long time ago,u may have to search if u wanna see it.
and thats my first time posting,so it contains many bugs,u could post it here so i can fix it.
thx
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 05-24-2005   #3 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
Sorry for double post(for real,i do this to increase my post,who know?),but i remembered that my tut is used for plain txt database.
so i will give u a example,u can code ones base on this:
PHP Code:
//do some mysql conenct here
$a=mysql_query("SELECT * FROM tablename limit('".$begin."','".$end."') "); 
see the "limit" ?what it does is to limit the record that queried from the query $a.
for example i have these in my database name :
num - name
1 - scott
2 - bill
3 - sam
4 - peter
5 - george
so if i query it and i limit(2,3)
the return value will be bill,sam and peter.
so all you have to do is increse or decrease the variables $begin adn $end.
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 05-24-2005   #4 (permalink)
Local Biorust Beast
 
Order's Avatar
 
Join Date: Oct 2003
Location: San Diego, CA, USA
Posts: 2,253

Send a message via AIM to Order Send a message via MSN to Order Send a message via Yahoo to Order
Pagination can get pretty complicated, and is complex.

ParaSnake has the right idea though, you need to have a start and an offset. The start is where to begin, and the offset is how many you want to pull.

This is more of an SQL issue then php, here is some code to generate your links, use the LIMIT SQL statement to limit the results, I am only showing how to generate how many pages you will need.

PHP Code:
$count "SELECT COUNT(*) FROM 'tutorials' WHERE section = '$sec'"// We do not want to limit, since we want a full number.
$res mysql_query($sql);
$count mysql_fetch_array($res);
$pages $count 10// Change 10 to your offset.
$pages ceil($pages); // Rounds it up.
for($i=1;$i == $pages;$i++)
{
   
$count = ($i 10) + // Change the 10 to your offset.
   
echo "<a href='page.php?start=$count&offset=10'>$i</a>"// Change 10 to offset.
}

// Done. 
Not the greatest sample, but is simple.. those will generate your page links, it is up to you to use SQL LIMIT to get the proper results.
__________________
Order is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Tutorial Trio! Man1c M0g Announcements 3 07-09-2005 09:15 AM
my new php sig scrowler HTML / PHP / ASP / JS 12 01-30-2005 01:00 AM
Php... Joe HTML / PHP / ASP / JS 35 06-22-2004 12:08 AM
Digital's Quick and Dirty Guide to PHP Order HTML / PHP / ASP / JS 15 05-05-2004 01:18 AM
PHP Help Needed... Young Spartan HTML / PHP / ASP / JS 1 12-02-2003 08:37 AM


All times are GMT +1. The time now is 08:03 AM.
Content Relevant URLs by vBSEO 3.2.0

Design & Content © BioRUST 2007 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT