Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 2nd, 2003, 06:38 PM
Registered User
Join Date: Aug 2003
Location: , , .
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:
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;    
Reply With Quote
  #2 (permalink)  
Old August 2nd, 2003, 07:00 PM
Registered User
Join Date: Aug 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Never mind... I figured it out myself.

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 02:50 AM.

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