I made a function that was to read from a database containing all of my VHS's and DVD's.
The function was supposed to list $moviesperpage movies on one page.
So if I got 100 movies, and $moviesperpage is set to 20, I would get five pages with 20 movies...
Sort of like google, but with movies instead of hits.
Anyway, my code doesn't work, and it seems to list up a random number of movies, instead of just "$moviesperpage" number of movies.
The code:
Code:
function read_db() {
global $db_connection, $moviesperpage, $PHP_SELF;
if(isset($_GET['start'])) {
$start = $_GET['start'];
$end = $start + $moviesperpage;
$limit = "$start , $end";
} else $limit = "0 , $moviesperpage";
$read_query = "SELECT * FROM divx ORDER BY name LIMIT $limit";
$result = mysql_query($read_query, $db_connection);
while ($query_data = mysql_fetch_row($result)) {
echo ("Title: " . $query_data[1]);
echo ("Genre: " . $query_data[2]);
echo ("Year: " . $query_data[3]);
echo ("Media: " . $query_data[5]);
echo "<A href=\"$PHP_SELF?action=edit&id=$query_data[0]\">Edit</A>\n";
}
$count_query = "SELECT * FROM divx";
$count = mysql_query($count_query, $db_connection);
$numberofrows = mysql_num_rows($count);
$page = 1;
$begin = 0;
$i = $numberofrows;
while ($i > 0) {
echo "<A href=\"$PHP_SELF?action=read&start=$begin\">$page</A> ";
$page = $page + 1;
$i = $i - $moviesperpage;
$begin = $begin + $moviesperpage;
}
}