How to create next button

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 624 Views - Last Post: 16 March 2014 - 09:22 AM Rate Topic: -----

#1 ben_jamin  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 10-March 14

How to create next button

Posted 10 March 2014 - 07:15 AM

I have a php code which retrieve mysql DB and display on screen result.
My DB contains 600 rows-
 $count = 600 

I want to display 10 rows each time on screen
 $limit = 10 


So when first open the site i load the first 10 rows
 onload="javascript:total_properties()" 


<script>
function total_properties()
{
	$.post('ajax/entire_list.php', {}, function(data)
	{
		$('#feedback').html(data);
	});
									
}
</script>



And the entire_list.php is-
<html>
<?php require '../db/connect.php'; ?>	
<?php
	$i = 0;
	$amount = 10;
	while ($i < $amount)
	{
		$result_photo 	= mysql_query ("select * from images");
		$photo 			= mysql_result ($result_photo,$i,"picture");
		$address_photo 	= "http://example.com/$photo";
?>
<div class="link-content-container">
	<img class="thumb" src="<?php print $address_photo ?>">
</div>
<?php $i++; ?>
<?php	}	?>
</html>



So far so good and the site is working fine and i see my first 10 rows.

Now my question is how to make the NEXT button to display the next 10 rows (11-20, 21-30, etc..)?

Is This A Good Question/Topic? 0
  • +

Replies To: How to create next button

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: How to create next button

Posted 10 March 2014 - 07:20 AM

http://www.dreaminco...-how-to-use-it/
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: How to create next button

Posted 10 March 2014 - 07:20 AM

Quote

how to make the NEXT button to display the next 10 rows

by using SQLís LIMIT clause.
Was This Post Helpful? 0
  • +
  • -

#4 ge∅  Icon User is offline

  • D.I.C Addict

Reputation: 81
  • View blog
  • Posts: 577
  • Joined: 21-November 13

Re: How to create next button

Posted 10 March 2014 - 07:35 AM

There are few things I should tell you

- mysql_query is depreciated. You should use mysqli_query() or the PDO object
- You shouldn't do a query inside of a loop. You are slowing your server down. You only need to do the query and fetch the results once, then you can create a loop to display data.
- You shouldn't include the html tag in entire_list.php, it's already in your main document
- It is sad that your content isn't displayed when Javascript is not available (it's not SEO friendly). You could at least include your entire_list.php file in your main page. If it's not a .php file, make it so or allow PHP parsing in .html files in a .htaccess
- You could use a $.get request in this cas, you don't need to post data.

To answer your question, you only need to pass 1 parameter to your POST or GET request (which would be your $i value - $limit being $i+10) to make it work, but as Dormilich says you need to use the LIMIT clause in your SQL query for the sake of performance.

This post has been edited by ge∅: 10 March 2014 - 07:37 AM

Was This Post Helpful? 1
  • +
  • -

#5 ben_jamin  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 10-March 14

Re: How to create next button

Posted 11 March 2014 - 12:35 AM

View Postge∅, on 10 March 2014 - 07:35 AM, said:

There are few things I should tell you

- mysql_query is depreciated. You should use mysqli_query() or the PDO object


I am taking your great tips one by one.

So i changed my entire mysql to mysqli but i dont find one thing-
How do i convert 'mysql_result'

This is the old code:
 $category = mysql_result ($sql_properties,$i,"category"); 


What i want is to find the category on a given row.
so if i have:
1. A
2. B
3. C
and i = 2 then the answer is B

thanks
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: How to create next button

Posted 11 March 2014 - 12:44 AM

oh, thatís simple.
$result = mysqli_query($con, $sql);
// some error checking later ...
$row = $result->fetch_row();
$item = $row[1]; // it's a zero-indexed array

Was This Post Helpful? 0
  • +
  • -

#7 ben_jamin  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 10-March 14

Re: How to create next button

Posted 11 March 2014 - 02:58 AM

View PostDormilich, on 11 March 2014 - 12:44 AM, said:

oh, thatís simple.
$result = mysqli_query($con, $sql);
// some error checking later ...
$row = $result->fetch_row();
$item = $row[1]; // it's a zero-indexed array


I dont believe it is what i asked, i guess it is my bad.
I will ask again-

-------|c1|c2|c3
row1 | a | b | c
row2 | d | e | f
row3 | g | h | i

How do i fetch any of the data inside?
Let's say i want the result to be row3&c2 = 'h'.
Was This Post Helpful? 0
  • +
  • -

#8 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: How to create next button

Posted 11 March 2014 - 03:04 AM

do you have a Primary Key in that table? if not it is near impossible to do as there is no real row number (in the sense of counting) in a DB (which doesnít make sense anyways).

to get a certain value off a DB youíd normally do
SELECT `field_of_interest` FROM the_table WHERE `key_field` = ?;

Was This Post Helpful? 0
  • +
  • -

#9 ben_jamin  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 10-March 14

Re: How to create next button

Posted 11 March 2014 - 03:18 AM

Guys thanks, it is was my bad.
I ran a general query instead of specific.
working fine now.

This post has been edited by Dormilich: 11 March 2014 - 03:19 AM

Was This Post Helpful? 0
  • +
  • -

#10 ge∅  Icon User is offline

  • D.I.C Addict

Reputation: 81
  • View blog
  • Posts: 577
  • Joined: 21-November 13

Re: How to create next button

Posted 11 March 2014 - 04:02 AM

Just in case you haven't thought of it, you could send ALL your data at once without markup to the client and let Javascript manage the pages. If you only need pagination for ergonomics, it will make your PHP script simpler and your website faster to react to user interactions.

Furthermore, don't forget that pagination is an old fashion way to display content and that, most of the time, it just gets in the way. For example, when I click on a topic in my subscribed topics, I hate having to click on the "last page" link to be able to view the latest replies. In this case, limiting the number of replies per page is a necessity to save bandwidth, but when the load is manageable you can try better display the data and allow the user to get an overview.
Was This Post Helpful? 0
  • +
  • -

#11 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: How to create next button

Posted 11 March 2014 - 05:06 AM

View Postge∅, on 11 March 2014 - 12:02 PM, said:

In this case, limiting the number of replies per page is a necessity to save bandwidth, but when the load is manageable you can try better display the data and allow the user to get an overview.

I donít think thatís the whole truth. if you have too many result sets, it is unmanageable by the user (would you like to scroll through a list of 10,000 entries?)
Was This Post Helpful? 0
  • +
  • -

#12 ben_jamin  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 10-March 14

Re: How to create next button

Posted 11 March 2014 - 05:49 AM

View Postge∅, on 11 March 2014 - 04:02 AM, said:

Just in case you haven't thought of it, you could send ALL your data at once without markup to the client and let Javascript manage the pages. If you only need pagination for ergonomics, it will make your PHP script simpler and your website faster to react to user interactions.

Furthermore, don't forget that pagination is an old fashion way to display content and that, most of the time, it just gets in the way. For example, when I click on a topic in my subscribed topics, I hate having to click on the "last page" link to be able to view the latest replies. In this case, limiting the number of replies per page is a necessity to save bandwidth, but when the load is manageable you can try better display the data and allow the user to get an overview.


I dont need pages <1>,<2>,<3>... on my screen nor <last page> <first page>
I just need <next> button to display the next x rows from the entire table.
Was This Post Helpful? 0
  • +
  • -

#13 ge∅  Icon User is offline

  • D.I.C Addict

Reputation: 81
  • View blog
  • Posts: 577
  • Joined: 21-November 13

Re: How to create next button

Posted 11 March 2014 - 06:26 AM

it's even worse ergonomically speaking ;)
Was This Post Helpful? 0
  • +
  • -

#14 ben_jamin  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 10-March 14

Re: How to create next button

Posted 11 March 2014 - 07:41 AM

View Postge∅, on 10 March 2014 - 07:35 AM, said:

There are few things I should tell you

- It is sad that your content isn't displayed when Javascript is not available (it's not SEO friendly). You could at least include your entire_list.php file in your main page. If it's not a .php file, make it so or allow PHP parsing in .html files in a .htaccess


I solved most of the cases here. thanks a lot
You wrote that JS hide data from SEO. did i get it right?
Was This Post Helpful? 0
  • +
  • -

#15 ge∅  Icon User is offline

  • D.I.C Addict

Reputation: 81
  • View blog
  • Posts: 577
  • Joined: 21-November 13

Re: How to create next button

Posted 11 March 2014 - 09:04 AM

Yep.

Robots parse your HTML code and follow your links. That's about it. If you import data in JS, it wont be seen.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2