Chatbox

You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1 database pages on 10/6/2012, 9:10 pm

grimofdoom

avatar

Member
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.

View user profile

2 Re: database pages on 12/6/2012, 10:42 am

LGforum

avatar

Moderator
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.

View user profile

3 Re: database pages on 13/6/2012, 9:48 pm

grimofdoom

avatar

Member
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.

View user profile

4 Re: database pages on 14/6/2012, 2:14 pm

LGforum

avatar

Moderator
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.

View user profile

Sponsored content


View previous topic View next topic Back to top  Message [Page 1 of 1]

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