Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/06/2021 in all areas

  1. This is a great point from @ginerjm Mixing "presentation" and "logic" is the best way to have hard to maintain code. PHP is intrinsically a templating product, in that you can put partial html scripts and include them easily. There are also numerous excellent and easy to integrate template systems. If you can separate the database/model related code from all the other code that is really just html, it will be easier to see how to approach things in a simple and maintainable way. The concept is certainly related to KISS and to breaking larger blocks of complicated interdependent code down into discreet functions that do one thing in a predictable way. From a database standpoint, your comment that "it creates a duplicate entry in my database if the value was already checked" also tells you that you are not using features of the database engine that will provide you data integrity. You can use constraints/indexes, as well as "UPSERTS" to help manage this. I would provide further examples, but I have no idea from your code snippets what your database looks like.
    1 point
  2. Stop throwing code at it with the hope that everything will start working and instead spend a minute thinking about what it is you're doing. It's a far more efficient method for solving problems. You've decided that $_POST has the page number of the results you want, and you put that value into $page. If you want to change page numbers then you need to include in the form data a new value for "page". The two buttons for previous and next are the things that the user will interact with, and they can each contain whatever new value it takes to make their actions happen. The previous button should use the previous page number and the next button should use the next page number - that would be $page-1 and $page+1 respectively, right? So you need to put the $page-1 and $page+1 numbers into the two buttons' values. We can worry about accidentally browsing to page 0 after that.
    1 point
  3. @gizmolathank you so much for making it clear, select form is more logical for this type and i ended up doing it. Thanks
    1 point
  4. #i dont know how to increment and decrement inside the value echo "<button type='submit' name= 'page' value = '' class='btn btn-primary'>PREV</button>"; echo "<button type='submit' name= 'page' value = '' class='btn btn-primary'>NEXT</button>"; You might be overthinking this. It's true that you can't change the $page variable inside the string, which isn't exactly what you should be doing anyways, but you can do things outside the string. See what you can come up with along those lines. Also don't forget that you still need the two if checks you had before for when the $page is >1 or <the page count.
    1 point
This leaderboard is set to New York/GMT-05:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.