How to create a load more button using php, pdo and oop

Heriberto Juarez

Im trying to create a button like the one in the youtube commentaries but i cant do it, I tried creating a static variable, so every time i press a button to load more the variable will be increased but it just can be increased once, maybe a for loop can help but i dont have any idea of how to implement it. (Im loading the ids i have saved in a mysql database but i will change the id for the commentaries i have in other database.) Screen shots:

Here´s the fist time the page is opened It works the first time i press the button but then it is not increased

<title>Pruebas</title>
<center>
<?php 
    require 'conexion.php';

    class Ver_prublicaciones extends Conexion{
        public function Ver_prublicaciones(){
            parent::__construct();
        }
        public function Ver($num){
            $sql="SELECT * FROM USUARIOS";
            $resultNum=$this->con->query($sql)->rowCount();

            $sql2="SELECT * FROM USUARIOS LIMIT 0,$num";
            $resultCon=$this->con->query($sql2);
            $array=$resultCon->fetchAll(PDO::FETCH_ASSOC);
            foreach ($array as $value){
                echo $value['ID'] . "<br>";
            }
        }

    }

    $numero;
    $numero=2;

    if(isset($_POST['cargar'])){
        $numero++;
    }


    $prueba=new Ver_prublicaciones();
    $prueba->Ver($numero);

?>

<form method="post">
    <input type="submit" name="cargar" value="Cargar más resultados">
</form>
</center>
Magnus Eriksson

You need to pass the current value of $numero to be able to increase it on every click.

PHP

// if we got a numero value posted, use that, otherwise set it to 2 as default
$numero = isset($_POST['numero']) ? $_POST['numero'] : 2;

if(isset($_POST['cargar'])){
    $numero++;
}

HTML

<form method="post">
    <input type="hidden" name="numero" value="<?= $numero ?>" />
    <input type="submit" name="cargar" value="Cargar más resultados">
</form>

Here we added the current value of $numero as a hidden field that gets passed on every click.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

OOP PHP + PDO - Is this how it should be?

From Dev

How to load iframes with load more button using javascript

From Dev

Refactoring code in OOP PHP and using PDO for mysql queries

From Dev

how to load more than one xml file using php

From Dev

Wordpress PHP How to add a Load More feature by using AJAX/JQUERY

From Dev

Making a load more button using only css

From Dev

working with "load more" button using scrapy

From Dev

How to set read more button using data from database in php

From Dev

How to set read more button using data from database in php

From Dev

How do i Make a load more button

From Dev

How do i Make a load more button

From Dev

How to add "more" button at the end of ListView to load more items?

From Dev

How to select "Load more results" button when scarping using Python & lxml

From Dev

How to select "Load more results" button when scarping using Python & lxml

From Dev

How to create simple load more in javascript

From Dev

How to display data in MYSQLI using OOP in PHP .

From Dev

how to design a has a relationship in oop (using php)

From Dev

How to load php files via $_GET variable OOP way

From Dev

How to create submit button in PHP using HTML forms?

From Dev

Ajax php/mysql Load More Button on Very Active feed

From Dev

Button in an while in PHP PDO

From Dev

Using JS OOP with PHP

From Dev

How to notice MySQL errors using PDO in PHP

From Dev

How to properly delete a row using PHP & PDO

From Dev

How to show table values in php using PDO

From Dev

how do i implement a "load more" button for meteor collection

From Dev

How to load more records of table on click of button in sapui5?

From Dev

How create button using reflection?

From Dev

Using PDO to CREATE TABLE

Related Related

  1. 1

    OOP PHP + PDO - Is this how it should be?

  2. 2

    How to load iframes with load more button using javascript

  3. 3

    Refactoring code in OOP PHP and using PDO for mysql queries

  4. 4

    how to load more than one xml file using php

  5. 5

    Wordpress PHP How to add a Load More feature by using AJAX/JQUERY

  6. 6

    Making a load more button using only css

  7. 7

    working with "load more" button using scrapy

  8. 8

    How to set read more button using data from database in php

  9. 9

    How to set read more button using data from database in php

  10. 10

    How do i Make a load more button

  11. 11

    How do i Make a load more button

  12. 12

    How to add "more" button at the end of ListView to load more items?

  13. 13

    How to select "Load more results" button when scarping using Python & lxml

  14. 14

    How to select "Load more results" button when scarping using Python & lxml

  15. 15

    How to create simple load more in javascript

  16. 16

    How to display data in MYSQLI using OOP in PHP .

  17. 17

    how to design a has a relationship in oop (using php)

  18. 18

    How to load php files via $_GET variable OOP way

  19. 19

    How to create submit button in PHP using HTML forms?

  20. 20

    Ajax php/mysql Load More Button on Very Active feed

  21. 21

    Button in an while in PHP PDO

  22. 22

    Using JS OOP with PHP

  23. 23

    How to notice MySQL errors using PDO in PHP

  24. 24

    How to properly delete a row using PHP & PDO

  25. 25

    How to show table values in php using PDO

  26. 26

    how do i implement a "load more" button for meteor collection

  27. 27

    How to load more records of table on click of button in sapui5?

  28. 28

    How create button using reflection?

  29. 29

    Using PDO to CREATE TABLE

HotTag

Archive