Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 2nd, 2003, 06:38 PM
Registered User
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Limiting MySQL data

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>&nbsp;";
        $page = $page + 1;
        $i = $i - $moviesperpage;
        $begin = $begin + $moviesperpage;    
    }
}
 
Old August 2nd, 2003, 07:00 PM
Registered User
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Never mind... I figured it out myself.

The LIMIT syntax was wrong, i used "LIMIT $start , $end". It should have been "LIMIT $start , $moviesperpage".





Similar Threads
Thread Thread Starter Forum Replies Last Post
limiting a macro to terminate after row 600 gauravhyd Excel VBA 1 May 29th, 2007 09:21 AM
Limiting Document Versions dasani20oz SharePoint Admin 1 October 23rd, 2006 03:55 PM
Bandwidth Control or Limiting using JSP draggy Pro JSP 3 July 21st, 2006 02:58 PM
Listing and limiting items from a database RPG SEARCH ASP.NET 1.0 and 1.1 Basics 11 August 3rd, 2004 04:37 PM
Limiting a TextBox MultLine gmachado VS.NET 2002/2003 1 November 2nd, 2003 12:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.