Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

twoodcc

macrumors P6
Original poster
Feb 3, 2005
15,307
26
Right side of wrong
i've made my own php site to stream my media, but more than that. i've got a mysql database setup that holds:

name, views, url, artist, category

and on the home page i've got the pages for different categories (music, movies, tv, music videos, videos) and i've got a stats page.

when you go to one of the pages, it lists the links to the files, ordered by views. (most views first).

when you click on a link, it goes to another php file that i have setup. the link had the id of that file, and so it pulls all the info from the database with that id. it then plays the file, shows the title and views, and i have a navigation bar at the top of the page.

basically what i'm trying to decide on is 2 things:

1. paging. right now i've got quite a few music files. you have to scroll down pretty far. how can i setup some sort of paging? i know how to use the limit function in mysql, so i could sort by views, and limit 20 or so, but when i click go to next page, how can i pick up from where it left off?

2. user system. right now i have manually add files to the database and folder on the server. should i setup a upload method with user/pass? i don't want people to be able to upload whatever to my site (just in case someone finds it). i know a little bit about sessions, but i'm not so sure i trust it (i've got some other sites with sessions, i'm not so sure they're that secure)

and any other recommendations. keep in mind this is really for just my personal use. but it does look somewhat similar to youtube (on the page where you play the media at least)

attached are some screenshots
 

Attachments

  • Screen shot 2010-05-19 at 8.28.30 PM.png
    Screen shot 2010-05-19 at 8.28.30 PM.png
    146.6 KB · Views: 105
  • Screen shot 2010-05-19 at 8.16.45 PM.png
    Screen shot 2010-05-19 at 8.16.45 PM.png
    17.2 KB · Views: 877

iMasterWeb

macrumors regular
Mar 15, 2009
158
0
I have a suggestion for number 1.

I've never actually done this before, but it should work...theoretically.

So what if you add a variable: $page. Page would hold the value of the current page. So to get the new list for the current page, you would do something like:

Code:
$page = $_GET['page'];
$number = 20 * $page; //number of items you want times page
$number2 = 20 * ($page - 1); //this gives us the number to start from

$list = mysql_query("SELECT * FROM myTable LIMIT '$number2', '$number'");

etc...

I think that it SHOULD work, but I haven't tried it. Anyways, let me know if it does work...or doesn't.
 

citizenzen

macrumors 68000
Mar 22, 2010
1,543
11,786
Here's a paging script that works for me. If memory serves I got it from an O'Reilly tutorial...or was it Codewalkers(?)...

PHP:
$host = ""; //your database host
$user = ""; // your database user name
$pass = ""; // your database password
$db = ""; // your database name

$filename = ""; // name of this file
$option = array (10, 25, 50, 100, 200);
$default = 100; // default number of records per page
$action = $_SERVER['PHP_SELF']; // if this doesn't work, enter the filename
$query = "Select * FROM foo order by id DESC"; // database query. Enter your query here
// end config---------------------------------
$opt_cnt = count ($option);
$go = $_GET['go'];
// paranoid
if ($go == "") {
$go = $default;
}
elseif (!in_array ($go, $option)) {
$go = $default;
}
elseif (!is_numeric ($go)) {
$go = $default;
}
$nol = $go;
$limit = "0, $nol";
$count = 1;
$connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect");
mysql_select_db ($db) or die ("Unable to select database $db");
// control query------------------------------
/* this query checks how many records you have in your table.
I created this query so we could be able to check if user is
trying to append number larger than the number of records
to the query string.*/
$off_sql = mysql_query ("$query") or die ("Error in query: $off_sql".mysql_error());
$off_pag = ceil (mysql_num_rows($off_sql) / $nol);
//--------------------------------------------
echo "<form name=\"form1\" id=\"form1\" method=\"get\" action=\"$action\">\r\n";
echo "<select name=\"go\" id=\"go\">\r\n";
for ($i = 0; $i <= $opt_cnt; $i ++) {
if ($option[$i] == $go) {
echo "<option value=\"".$option[$i]."\" selected=\"selected\">".$option[$i]."</option>\r\n";
} else {
echo "<option value=\"".$option[$i]."\">".$option[$i]."</option>\r\n";
}
}
echo "</select>\r\n";
echo "<input type=\"submit\" name=\"Submit\" id=\"Submit\" value=\"Go\" />\r\n";
echo '<br />';
echo '<br />';
$off = $_GET['offset'];
//paranoid
if (get_magic_quotes_gpc() == 0) {
$off = addslashes ($off);
}
if (!is_numeric ($off)) {
$off = 1;
}
// this checks if user is trying to put something stupid in query string
if ($off > $off_pag) {
$off = 1;
}
if ($off == "1") {
$limit = "0, $nol";
}
elseif ($off <> "") {
for ($i = 0; $i <= ($off - 1) * $nol; $i ++) {
$limit = "$i, $nol";
$count = $i + 1;
}
}
echo "<br />";
echo "\r\n";
for ($i = 1; $i <= $off_pag; $i ++) {
if ($i == $off) {
echo "<span class=\"offsetActive\">$i</span> \r\n";
} else {
echo "<span class=\"offset\"><a href=\"$filename?offset=$i&go=$go\">$i</a></span> \r\n";
}
}
echo "<br />\r\n";
echo '<br />';
if ($off <> 1) {
$prev = $off - 1;
echo "< <a href=\"$filename?offset=$prev&go=$go\">prev</a>   || \r\n";
}
echo "Page $off of $off_pag \r\n";
if ($off < $off_pag) {
$next = $off + 1;
echo "||   <a href=\"$filename?offset=$next&go=$go\">next</a> > \r\n";
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.