database pages

View previous topic View next topic Go down

grimofdoom
grimofdoom
Member
Member
Forum Posts : 106
Member Since : 2012-03-06

Postgrimofdoom 10/6/2012, 7:10 pm

I am getting ready to create a video website that will have tons of videos. I will(once i get a host(might get bluehost)) use database to store the urls and such. What would php script would i use to tell page that when the number on page =# to put it on another page...ect. I will put more and more in so i need the script so i can continuesly add without worry.
LGforum
LGforum
Moderator
Forum Posts : 77
Member Since : 2011-11-12

PostLGforum 12/6/2012, 8:42 am

Not sure what you mean.

Also, you can't use video's from other sites... thats copyright.
You'd have to to write upload scripts so the video's are stored on your server.
grimofdoom
grimofdoom
Member
Member
Forum Posts : 106
Member Since : 2012-03-06

Postgrimofdoom 13/6/2012, 7:48 pm

1. they are not anyone elses but me and my friends videos. 2. The host has an upload feature(that im hoping to get), though i didnt mention it, i did think of that after words but didnt remember to even post it. But how do i do the pagnation stuffs.
LGforum
LGforum
Moderator
Forum Posts : 77
Member Since : 2011-11-12

PostLGforum 14/6/2012, 12:14 pm

There's a lot involved with pagination depending on how you want it.

Most pagination scripts will include a starting point in the query string of the URL. This starting point can either be a database record or a page number (to then figure out the database record).

Here's some commented PHP for example, of how you'd do pagination with Posts in a thread. The example displays how to 10 posts per page, and displays all the page numbers. Its very simplified too.
Code:

# Get the starting number. If none is provided then start at 0.
$start = isset($_GET['start']) ? $_GET['start'] : 0;

# Get the 15 posts for this page.
$q = mysql_query('SELECT * FROM posts ORDER BY time LIMIT '.$start.', 10');

# Notice the LIMIT set in the SQL. The 10 represents to only pull a maximum of 10 rows.
# the $start figure is concatenated in. So this would be LIMIT 0, 10
# bla bla bla do something with those 10 posts.

# Now the pagination bit. How many rows altogether?
$total = mysql_query('SELECT * FROM posts');
$total = mysql_affected_rows($q);

# Lets say there is a total of 35 posts. Thats 4 pages. 3 full, and 1 with 5 on.
$pages = $total / 10;  //this would equal 3.5
$pages = ceil( $total ); //round it up to 4.

# Create the pagination html
$pagination = '<div class="pagination">'
for($i = 0; $i < $pages; $i++)
{
  $pagination .= '<a href="/url?start=' .($i*10).'">Page '.($i+1).'</a>';
}
$pagination .= '</div>';

# pagination variable now equals:
# <div class="pagination">
#  <a href="/url?start=0">Page 1</a>
#  <a href="/url?start=10">Page 2</a>
#  <a href="/url?start=20">Page 3</a>
#  <a href="/url?start=30">Page 4</a>
# </div>

After reading through the code, you'll hopefully see how and why it works.

Lets look at the page 3 link and take it through the example: /url?start=20
So $start will equal 20.
The SQL will be SELECT * FROM posts ORDER BY time LIMIT 20, 10
This means start at row 20, and only get 10. Therefore displaying from 20 - 30.

This is the basics, there is much more to it when you don't want to show all the page, but instead have like '...' and stuff. Displaying the current page. Having a Last, Next Previous option etc.

A lot of people don't actually know how much is involved with creating pagination.
Sponsored content

PostSponsored content

View previous topic View next topic Back to top

Create an account or log in to leave a reply

You need to be a member in order to leave a reply.

Create an account

Join our community by creating a new account. It's easy!


Create a new account

Log in

Already have an account? No problem, log in here.


Log in

 
Permissions in this forum:
You cannot reply to topics in this forum