Result Pages, Missing Data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jeigh
    New Member
    • Jul 2007
    • 73

    Result Pages, Missing Data

    I did not write this script myself and am having a bit of trouble with it, it's working fine except it's missing the first piece of data for each page. This being data for each user.

    For example, there are 3 pages with 5 usernames on each, the top username is missing on every page so it is only showing 12 when it should be showing 15.

    I was wondering if anyone could tell me what could cause this in the following script:

    NOTE: The where section is commented out as I am not using it.

    Code:
    <? 
       include('header.php');
       include('navigation.php');
       include('content.php');
    
    function pagenav() {
        global $limit,$offset,$numpage,$where;
        if ($where) {
            $safewhere=urlencode($where);
        }
    	
            if ($offset>=$limit) {
                $newoff=$offset-$limit;
                
                echo "<a href=\"$PHP_SELF?offset=$newoff&where=$safewhere\">
                    &lt;-- PREV</a>
                    ";
            } else {
                echo "&lt;-- PREV";
            }
    
            echo "&nbsp; ";
    
            for ($i=1;$i<=$numpage;$i++) {
                if ((($i-1)*$limit)==$offset) {
                    print "$i ";
                } else {
                    $newoff=($i-1)*$limit;
    
                    echo "<a class=\"pageno\" href=\"$PHP_SELF?offset=$newoff&where=$safewhere\">
                        $i</a> ";
                }
            }
            echo "&nbsp;";
            if ($offset!=$limit*($numpage-1)) {
                $newoff=$offset+$limit;
                echo "<a href=\"$PHP_SELF?offset=$newoff&where=$safewhere\">
                    NEXT--&gt;</a>
                    ";
            }else{
                echo "NEXT--&gt;";
            }
    
    } // END FUNCTION
    
    
    // set this to the number of results you wish on each page
    $limit=3; 
    
    // if no offset has been passed, offset should be 0
    if (!$offset) {
        $offset=0; 
    }
    
    /*
    if (!$where) // where was not passed {
        if (empty($one) || empty($two)) {
               // some error handling as $one 
            //and/or $two not passed to initial page
        }
        $where="$one|$two";
    
    // NOTE: if a pipe (|) may be in the value 
    //of $one or $two, use a different delimiter
    $data=explode('|',$where); 
    $query_where="where one='$data[0]' AND two='$data[1]'";
    */
    
    $result=mysql_query("select count(*) from users");
    list($numrec)=mysql_fetch_row($result);
    #calc num pages
    $numpage=intval($numrec/$limit);
    if ($numrec%$limit) $numpage++; // add one page if remainder
    
    ?>
    <form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
    <input type="text" name="reqprof" value="Enter Username" />
    <input type="submit" name="submit" value="Get Link" />
    </form>
    <?
    if($_POST['reqprof']){
    $reqname = $_POST['reqprof'];
    $userlink = "profile.php?user=$reqname";
    echo "<a href=\"$userlink\">View Profile</a>";
    }
    ?>
    <table class="browse">
    <?
    
    $result=mysql_query("select * from users limit $offset,$limit");
    
    $row=mysql_fetch_assoc($result);
    while($row=mysql_fetch_array($result))
    { 
    echo "<tr><td class=\"browse\">";
    echo "<div class=\"profiletext\">";
    echo $row['username'];
    echo "</div>";
    echo "<br />";
    ?>
    <img src="uploads/photo/<? echo $row['photo']; ?>" alt="<? echo $row['username'] ?>'s Display Picture" />
    <?
    echo "</td>";
    ?>
    <td class="browse"><a href="profile.php?user=<? echo $row['username'] ?>">Profile</a></td></tr>
    <?
    }
    ?>
    </table>
    <br />
    <?
    
    if ($numpage>1) {
        pagenav();
        print "<p>";
    }
    
       include('endcontent.php');
       include('advert.php');
       include('footer.php'); 
    ?>
  • Jeigh
    New Member
    • Jul 2007
    • 73

    #2
    Any ideas of what could cause that?

    Comment

    • dafodil
      Contributor
      • Jul 2007
      • 389

      #3
      Originally posted by Jeigh
      Any ideas of what could cause that?
      Can you try to run that code and see if there are errors?
      If there are errors then that's caused by the missing part...

      Comment

      • Jeigh
        New Member
        • Jul 2007
        • 73

        #4
        There are no errors, I have the system running properly on my site now, it's just that top entry on each page that's missing (no errors or anything, it's just as if it wasn't in the database). Which I can't seem to figure out.

        Comment

        • code green
          Recognized Expert Top Contributor
          • Mar 2007
          • 1726

          #5
          Code:
          select * from users limit $offset,$limit");
          Echo out this statement to see if it is the query you expect

          Comment

          • Jeigh
            New Member
            • Jul 2007
            • 73

            #6
            When I echo that line it gives me "select * from users limit 0,3"

            Oh and as you'd expect since the top entry is missing for each page, each page displays 2 not 3.

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              Line 92 (in the code above) should be removed.

              Comment

              • Jeigh
                New Member
                • Jul 2007
                • 73

                #8
                Thank You very much, it seems to be working perfectly now :)

                Comment

                • Motoma
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3236

                  #9
                  Originally posted by Jeigh
                  Thank You very much, it seems to be working perfectly now :)
                  Glad to help, come back if you have any more questions.

                  Comment

                  Working...