SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, i wrote the following script after reading freddydoesphp's post at http://www.sitepointforums.com/showt...it#post112126.

    i got it work fine for increments of 1.
    and i think i have to work fine for different increments also. but i'm not sure.

    it kept erroring out when it reached the last page that it's supposed to display bec it kept looking for the next row in the db that didn't exist (bec the row before it was the last one)

    so my humble request is that someone would be kind enough to go over my code real quick and tell me 2 things:

    1) if i am overlooking something obvious that will result in the script erroring out when it reaches the last row in the db (or at all)

    and

    2) if someone knows of a way that i could display the range of the records being viewed as opposed to the id number of the record. (ex: you are viewing record number $var thru $var2)

    here is the code :

    Code:
    <html>
    <head><title>title</title>
    </head>
    <body>
    <?
    
    <--- connection variables go here --->
    
    /////////////////////////////////
    //SET LIMITS
    /////////////////////////////////
    
    if (!isset($limit1)) $limit1 = 0;
    
    //////////////////////////////////////////////////////////////////////
    /*SET THIS TO WHAT YOU WANT THE NUMBER OF RESULTS PER PAGE TO BE */
    /////////////////////////////////////////////////////////////////////////
    
    $limit2 = "7";
    
    /////////////////////////////////////////////////////////////////////////
    
    @mysql_select_db("$DBName") or die("Unable to select database $DBName");
    $sqlquery = "SELECT * FROM $table WHERE ID >= '0' LIMIT $limit1, $limit2";
    $result = mysql_query($sqlquery);
    $number = mysql_numrows($result);
    
    $i = 0;
    
    if ($number < 1) {
    print "<CENTER><P>There Were No Results for Your Search</CENTER>";
    }
    else {
    while ($number > $i) {
    $variable = mysql_result($result,$i,"fieldname");
    $variable2 = mysql_result($result,$i,"fieldname2");
    $variable3 = mysql_result($result,$i,"fieldname3");
    $variable4 = mysql_result($result,$i,"fieldname4");
    
    /////////////////////////
    // START OF OUTPUT
    /////////////////////////
    
    print " <---- this is where the html template with the outputted variables go ----->
    
    "
    ;
    $i++;
    }
    }
    /////////////////////////////////////////////////
    $result = mysql_query("SELECT * FROM $table");
    $count = (mysql_num_rows($result));
    
    if ($limit1 != 0) { 
    printf('<center><a href="%s?limit1=%s">previous %s results</a></center>', $PHP_SELF, $limit1 - $limit2, $limit2); 
    } 
    printf('<center><font class="textorange">  You are viewing record number %s  </font></center>', mysql_result($result, $limit1, 0)); 
    
    if ($limit1 != $count - 1 && $limit1 < $count - $limit2) { 
    printf('<center><a href="%s?limit1=%s">next %s results</a></center>', $PHP_SELF, $limit1 + $limit2, $limit2); 
    }
    
    
    /////////////////////////////////////////////////////
    ?>
    </BODY>
    </HTML>
    any help would be enormously appreciated.
    and i will praise your name and your greatness for all to hear
    . . . chris

  2. #2
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't really understand what is wrong as you said it gave you an error msg. Give me that msg, it'd be much easier.
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I used your exact code, of course changing some tablenames and field names and it worked perfect, although since you are uusing groups of 7 there is amuch easier way to accomplish this using mysql_fetch_array()
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, my fault

    ok, at this point, there are 7 records in the db. this will obviously change as time goes on.
    the script worked ok if i wanted to display 1 record per page (ie. limit =1)

    but when i used a limit that didn't divide into 7 equally such as 2 or 3, i would get the following error: (this is before i "fixed" it)

    Code:
    Warning: Unable to jump to row 8 on MySQL result index 3 in /www/bostoncreative/php-bin/listingcurrent2.php on line 194
    line 194 is where this piece of code would be:

    Code:
    printf('<center><font class="textorange">  You are viewing record number %s  </font></center>', mysql_result($result, $limit1, 0));
    so everytime that $limit was greater than the number of records (or rows) in the db, in this case that would be 7, i would get the warning about being "unable to jump to row 8".

    now, i think i fixed it with this line in the posted version of the script, but i'm not sure:

    Code:
    if ($limit1 != $count - 1 && $limit1 < $count - $limit2) { 
    printf('<center><a href="%s?limit1=%s">next %s results</a></center>', $PHP_SELF, $limit1 + $limit2, $limit2); 
    }
    my concern is that ok, i got it to work for this situation (number or records and limits), will it work if i have say 750 records or 2000 or whatever?

    i hope that i was able to explain it a little bit better.
    Last edited by atomicmunky; Mar 2, 2001 at 00:36.
    . . . chris

  5. #5
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nothing ???
    . . . chris


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •