473,498 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Avoid duplicate value in PHP MySQL pagination with rand()

123 New Member
I have a pagination that load more when I click on the load more button, which I got from the below URL http://makitweb.com/load-more-results-with-jqueryajax-and-php/

Whenever I add RAND() it always duplicates the value.


index.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $rowperpage = 10;
  4.  
  5. $allcount_query = "SELECT count(*) as allcount FROM users order by id";
  6. $allcount_result = mysql_query($allcount_query);
  7. $allcount_fetch = mysql_fetch_array($allcount_result);
  8.  $allcount = $allcount_fetch['allcount'];
  9.  
  10. $query = "select * from users order by RAND() asc limit 0,$rowperpage ";
  11. $result = mysql_query($query);
  12. while($row = mysql_fetch_array($result)){
  13. ?>
  14.  
  15. <div><h1><?php echo $row['id']; ?></div>
  16.  
  17. <?php
  18. }
  19. ?>
  20.  
  21. <h1 class="load-more">Load More</h1>
  22. <input type="hidden" id="row" value="0">
  23. <input type="hidden" id="all" value="<?php echo $allcount; ?>">

getData.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $row = $_POST['row'];
  3. $rowperpage = 10;
  4.  
  5.  
  6. $query = 'SELECT * FROM users ORDER BY id limit '.$row.','.$rowperpage;
  7. $result = mysql_query($query);
  8.  
  9. $html = '';
  10. while($row = mysql_fetch_array($result)){
  11.  
  12. $html .= '<div><h1>'.$id.'</h1></div>';
  13.  
  14. }
  15. ?>
Nov 21 '17 #1
1 2803
Luuk
1,047 Recognized Expert Top Contributor
"Whenever I add RAND() it always duplicates the value."
Which value is duplicated?

Also about line #5, there is no need to do an 'order by' here, because the COUNT will not be different if it's ordered or not ....
Dec 6 '17 #2

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

Similar topics

3
4029
by: audj | last post by:
Hello, I am trying to use a subquery to avoid duplicate entries when someone submits a form to subscribe to a mailing list. So I want to check if the email exists before adding the record. ...
5
5428
by: mercea | last post by:
hi all, How do i avoid duplicate records on my database? i have 4 textboxes that collect user information and this information is saved in the database. when a user fills the textboxes and clicks...
1
9672
by: Carmine [www.thetotalsite.it] | last post by:
Hi, I am using ASP.Net 2.0 with the MySQL Connector .Net 5.1.2.2. I added these lines to the web.config to make the connector.net able to handle the SqlConnection object (and so to bind it to a...
5
3235
by: lyne_asp | last post by:
Hello everbody, Please help me to remove the duplicate value. I have this code Do until objRSEmail.eof tgroup = objRSEmail("tEmailName")&"@city.com;"&tgroup ...
4
2429
by: lucky13 | last post by:
Dear All, can u help in how to check the duplicate value in the listview control before adding new in the list. Regards Lucky13
3
5455
by: spl | last post by:
What is the fastest way to find a duplicate value in an array of 10 elements. I have to find just any one first occurrence of the duplication. Lets say I have ary={10, 20, 40, 90, 30, 60, 35, 40,...
1
1574
by: krishanusasmal | last post by:
I am learning in PHP and HTMl. AND XAMPP. when i inserting any duplicate value. I want to display message with duplicate message or the data already exist or something like that. Plz. help me.
1
911
by: inder | last post by:
I have two fields Phone1 and Phone2 in my form. I want Phone1 after update to check its duplicate value in both phone1 and phone2. Similarly Phone2 to check phone2's duplicate value in both phone1...
5
1155
by: hvsummer | last post by:
ok, After I used MVFs (Multivalue Fields) to query thing, I got alittle problem with it, It created duplicate value in query, can anyone spot out the problem and give some solution idea ? the...
8
1088
by: hvsummer | last post by:
ok, to be simple, I'll ask short question with short detail. I have 2 table. table 1 with and ID Date 1 -- 1 1 -- 2 1 -- 3 2 -- 1
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7203
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...
1
6885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.