Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

folcotandiono's avatar

pagination

I have a form that i used to add data to database, then i have a value that need to be choose from a database table, what i have in my mind is make a button, then after i click the button, it pop up a modal dan have pagination table, i already do this, but after clicking next it goes to another page. Any help would be appreciated. I didn't have another idea in my mind beside pagination.

0 likes
29 replies
topvillas's avatar

If you're using Vue then add the prevent modifier to the click event.

<button @click.prevent="method">Next</button>

But why not use an autosuggest field?

folcotandiono's avatar

I have a column in my database and the column's value is id from another table, is there a way to get this value without pagination

topvillas's avatar

Getting things from the database has nothing to do with pagination. Pagination is just a presentation option.

If you want to make it really simple then use a select populated with the data from the other table.

folcotandiono's avatar

i want to use pagination, but it is too complicated.. do u have any suggestion?

topvillas's avatar

Pagination isn't complicated. If you want some help then you'll need to give us more than a vague paragraph about what you want to do.

Show us your existing code and we might be able to expand and help you out.

jlrdw's avatar

Show actual and properly formated code you have tried.

folcotandiono's avatar

i already tried pagination code, but it can only be one pagination inside view, i want many pagination inside my view

folcotandiono's avatar

just answer this... can i put multiple pagination inside a view?

jlrdw's avatar

There are tutorials on youtube showing how to achieve that. Normally when asking here, user has at least the knowledge to try some code, then if having trouble ask. You don't even have any code you have tried.

Some folks on the forum have years of experience, you can't get 15 years of experience from here, you need to have some basics first.

folcotandiono's avatar

I am sorry sir, i use codeigniter.. that's why.. i dont find any better forum

Snapey's avatar

This is what I think the OP wants

Looking at web page, click a button

A modal window appears. Inside this modal window should appear a paginated list.

When one of the paginated links in the modal window is clicked, the whole page reloads.

(as you would expect)

So, with a modal, they are probably going to need to use ajax to bring in the content from the next page, or page through the already loaded content with javascript.

If there are less than several hundred rows then I would probably load the lot client side and page locally with datatables.net, depending on the size of the data set

jlrdw's avatar

I have actually paginating with Ajax as well but at the end of the day I like regular paginaton better, no ajax.

folcotandiono's avatar

If laravel or codeigniter provide pagination, why use ajax?

jlrdw's avatar

Why don't you come on over to the laravel side?

I have found 5 good frameworks, i like in this order:

  • One I did custom
  • laravel and Nova framework 4
  • Yii 2
  • cakephp

Note nova 4 draws from ideas of an older SMVC framework and laravel and Yii. In fact Taylor is also credited.

Of course symphony is due a lot of credit in both as their components are used.

But really the pagination you can probably find a youtube video to help.

Without posted code you have tried, it's hard to help you.

Pagination is easy in laravel, unless a complex query where a custom length aware paginator would be required. But in routine queries Taylor has done the work for us.

jlrdw's avatar

In example it's a pop-up window but I choose from table but Ajax is working in background to fIll the fields. Sounds like you need to learn some basic Ajax as well. But like I said there was some good YouTube videos on the basics of this kind of thing. Search and view a few and try some code then come back.

folcotandiono's avatar

@jlrdw how u pass data from current window to another, and from the another window to current window?? another window don't connect to current window from what i see, so how do u pass the data?

jlrdw's avatar

It is a little involved but as I said there are some good YouTube videos out there. The Ajax in the background works no matter the language PHP Java Etc. On tablet now will try to explain better on desktop later

folcotandiono's avatar

How do u make the input on current window value changed based on click event on another window?

jlrdw's avatar
jlrdw
Best Answer
Level 75

Beside the field /s you want looked up you have code to open the lookup table:

echo '<a href="JavaScript:void(0);" onclick="WriteBack()">Click Me</a>';

Which calls this code to open and center new popup window

function WriteBack() {
    var iMyWidth;
    var iMyHeight;
    iMyWidth = (window.screen.width / 2) - (250 + 10);
    iMyHeight = (window.screen.height / 2) - (250 + 50);
    var map = window.open("/pets/owner/indexsch", "map", "status=no,height=500,width=500,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
}

The table that's loaded has unique row id's so you can call this now once a row id is clicked

<script>

$(function () {
    function makeAJAXRequest (text) {
        $.ajax({
            url: 'owner/getowner',
            type: 'GET',
            dataType: 'json',
            data: { id: text },
            success: processSuccess
        });
    }

    function processSuccess (data) {
    
        $.each(data, function (key, value) {
            var id = '#' + key,
                elem = window.opener.$(id);
                   
            if (key === 'ocheck') {
                elem.attr('checked', value === '1');
            }
            else {
                elem.val(value);
            }
        });

        self.close();
    }

    $("#myTable td:nth-child(1)").click(function (event) {
        event.preventDefault();

        var $td = $(this).closest('tr').children('td');
        var currentCellText = $td.eq(0).text();
        
        makeAJAXRequest(currentCellText);
    });
});



</script>

This in turn retrieves the correct owner from database, note old example, not laravel code, but basics are the same or similar.

    public function getowner()
    {
        $this->chkLog();
        $ownerid = $_GET['id'];
        $row = end($this->Owner->getownerList2($ownerid));
        // above line calls model to retrieve data
        $petowner = $row->oname;
        $ostreet = $row->ostreet;
        $odate = $row->odate;
        $ocheck = $row->ocheck;

        echo json_encode(compact('ownerid', 'petowner', 'ostreet', 'odate', 'ocheck'));
      //echo json_encode($row);
    }

just a quick example, security would need to be implmented, etc.

But you really need to take some tutorials and view some youtube videos on ajax and json return. Doesn't even have to be json, even an array return works.

There are other options for you, like select2 https://select2.org/

1 like

Please or to participate in this conversation.