473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Result Pages, Missing Data

73
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.

Expand|Select|Wrap|Line Numbers
  1. <? 
  2.    include('header.php');
  3.    include('navigation.php');
  4.    include('content.php');
  5.  
  6. function pagenav() {
  7.     global $limit,$offset,$numpage,$where;
  8.     if ($where) {
  9.         $safewhere=urlencode($where);
  10.     }
  11.  
  12.         if ($offset>=$limit) {
  13.             $newoff=$offset-$limit;
  14.  
  15.             echo "<a href=\"$PHP_SELF?offset=$newoff&where=$safewhere\">
  16.                 &lt;-- PREV</a>
  17.                 ";
  18.         } else {
  19.             echo "&lt;-- PREV";
  20.         }
  21.  
  22.         echo "&nbsp; ";
  23.  
  24.         for ($i=1;$i<=$numpage;$i++) {
  25.             if ((($i-1)*$limit)==$offset) {
  26.                 print "$i ";
  27.             } else {
  28.                 $newoff=($i-1)*$limit;
  29.  
  30.                 echo "<a class=\"pageno\" href=\"$PHP_SELF?offset=$newoff&where=$safewhere\">
  31.                     $i</a> ";
  32.             }
  33.         }
  34.         echo "&nbsp;";
  35.         if ($offset!=$limit*($numpage-1)) {
  36.             $newoff=$offset+$limit;
  37.             echo "<a href=\"$PHP_SELF?offset=$newoff&where=$safewhere\">
  38.                 NEXT--&gt;</a>
  39.                 ";
  40.         }else{
  41.             echo "NEXT--&gt;";
  42.         }
  43.  
  44. } // END FUNCTION
  45.  
  46.  
  47. // set this to the number of results you wish on each page
  48. $limit=3; 
  49.  
  50. // if no offset has been passed, offset should be 0
  51. if (!$offset) {
  52.     $offset=0; 
  53. }
  54.  
  55. /*
  56. if (!$where) // where was not passed {
  57.     if (empty($one) || empty($two)) {
  58.            // some error handling as $one 
  59.         //and/or $two not passed to initial page
  60.     }
  61.     $where="$one|$two";
  62.  
  63. // NOTE: if a pipe (|) may be in the value 
  64. //of $one or $two, use a different delimiter
  65. $data=explode('|',$where); 
  66. $query_where="where one='$data[0]' AND two='$data[1]'";
  67. */
  68.  
  69. $result=mysql_query("select count(*) from users");
  70. list($numrec)=mysql_fetch_row($result);
  71. #calc num pages
  72. $numpage=intval($numrec/$limit);
  73. if ($numrec%$limit) $numpage++; // add one page if remainder
  74.  
  75. ?>
  76. <form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
  77. <input type="text" name="reqprof" value="Enter Username" />
  78. <input type="submit" name="submit" value="Get Link" />
  79. </form>
  80. <?
  81. if($_POST['reqprof']){
  82. $reqname = $_POST['reqprof'];
  83. $userlink = "profile.php?user=$reqname";
  84. echo "<a href=\"$userlink\">View Profile</a>";
  85. }
  86. ?>
  87. <table class="browse">
  88. <?
  89.  
  90. $result=mysql_query("select * from users limit $offset,$limit");
  91.  
  92. $row=mysql_fetch_assoc($result);
  93. while($row=mysql_fetch_array($result))
  94. echo "<tr><td class=\"browse\">";
  95. echo "<div class=\"profiletext\">";
  96. echo $row['username'];
  97. echo "</div>";
  98. echo "<br />";
  99. ?>
  100. <img src="uploads/photo/<? echo $row['photo']; ?>" alt="<? echo $row['username'] ?>'s Display Picture" />
  101. <?
  102. echo "</td>";
  103. ?>
  104. <td class="browse"><a href="profile.php?user=<? echo $row['username'] ?>">Profile</a></td></tr>
  105. <?
  106. }
  107. ?>
  108. </table>
  109. <br />
  110. <?
  111.  
  112. if ($numpage>1) {
  113.     pagenav();
  114.     print "<p>";
  115. }
  116.  
  117.    include('endcontent.php');
  118.    include('advert.php');
  119.    include('footer.php'); 
  120. ?>
  121.  
Jul 17 '07 #1
8 1387
Jeigh
73
Any ideas of what could cause that?
Jul 17 '07 #2
dafodil
392 256MB
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...
Jul 17 '07 #3
Jeigh
73
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.
Jul 17 '07 #4
code green
1,726 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. select * from users limit $offset,$limit");
Echo out this statement to see if it is the query you expect
Jul 17 '07 #5
Jeigh
73
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.
Jul 17 '07 #6
Motoma
3,237 Expert 2GB
Line 92 (in the code above) should be removed.
Jul 17 '07 #7
Jeigh
73
Thank You very much, it seems to be working perfectly now :)
Jul 18 '07 #8
Motoma
3,237 Expert 2GB
Thank You very much, it seems to be working perfectly now :)
Glad to help, come back if you have any more questions.
Jul 18 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: David Walker | last post by:
Hi I have a Microsoft SQL database I can use (also mySQL, so if you know how to do this in mySQL that is just as useful). The database can only be accessed from webpages hosted on the same server...
5
by: Steven T. Hatton | last post by:
If you happen to have Accelerated C++ by Koenig and Moo, and haven't gotten around to reading it, I suggest you count the pages between page 18 and page 51. I came up with zero. This is very...
5
by: rob | last post by:
Hi to all. I am pretty new to using Access and am having a problem I hope someone can help me with. I want to access a MS-Access database from a web page. I have managed to get it "sort" of...
14
by: multiformity | last post by:
So I have been working on an opensource project for a while, and decided to really try to make it look better after focusing on the functionality most of this time. Up to now, I have simply used a...
6
by: Bill | last post by:
Hi I am trying to get my listbox items to print if they stream past the one page mark. my code is working for one page of information (if the e.hasmorepages) is not there. But I am having...
3
by: coder | last post by:
I am new to programming in PHP however, this should be a pretty straight forward answer. I have three queries that I am pulling for a content form page. 1) The Author List 2) The Content Page...
13
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any...
5
by: gom | last post by:
I am an amatuer asp.net programmer so I hope this question isn't to dumb. I am having difficulty with my understanding of session state. I have an application that stores some values in the...
1
by: deshaipet | last post by:
Hi friends - I created a automatic storage tablespace with a pagesize of 16 K and initial size of 64 MB. create large tablespace test_tbsp1 pagesize 16k managed by automatic storage autoresize...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.