Smartening up my php/html/mysql interaction...
Posted: Sat Oct 17, 2009 3:42 pm
With help from in here I now have an html form that lets me retrieve data from MySQL and display the information on the form. BUT, I'm not happy with the methodology I used and am hoping y'all can smarten me up...
Currently the process is:
form displays empty
user hits "find" button then fills in information in one or more fields
user hits "submit" button and php code connects to the database and returns the first record of the set
user hits "next" button and a counter is incremented and the next record gets returned
my query is "SELECT * FROM <table> WHERE <predicate> limit <currentrow> , 1"
repeat for entire bunch... This works but it's gross..... It means making a round trip to the database EVERY time the user wants either the next or previous record. The predicate gets set in the find pass, the currentrow gets incremented or decremented based on next or previous button......
Is there a way for me to retrieve all the records and process them in php/html to move through them by button press? Currently, based on advice in here, my php code is at the top of my file with the html below, so every time I press a button the file gets run through. I have a simple "if-then-else" to look at the button and do what's needed, but I figure there's got to be a more efficient way of displaying the retrieved records that getting them 1 at a time.....
In the "old" days this would be a MAJOR bozo nono and I'd what any of my designers that did something this inefficient. Now, with the astronomical slowness of shoving things around the web compare to hitting the database repeatedly maybe it's no longer an issue but I figured I'd ask...
Currently the process is:
form displays empty
user hits "find" button then fills in information in one or more fields
user hits "submit" button and php code connects to the database and returns the first record of the set
user hits "next" button and a counter is incremented and the next record gets returned
my query is "SELECT * FROM <table> WHERE <predicate> limit <currentrow> , 1"
repeat for entire bunch... This works but it's gross..... It means making a round trip to the database EVERY time the user wants either the next or previous record. The predicate gets set in the find pass, the currentrow gets incremented or decremented based on next or previous button......
Is there a way for me to retrieve all the records and process them in php/html to move through them by button press? Currently, based on advice in here, my php code is at the top of my file with the html below, so every time I press a button the file gets run through. I have a simple "if-then-else" to look at the button and do what's needed, but I figure there's got to be a more efficient way of displaying the retrieved records that getting them 1 at a time.....
In the "old" days this would be a MAJOR bozo nono and I'd what any of my designers that did something this inefficient. Now, with the astronomical slowness of shoving things around the web compare to hitting the database repeatedly maybe it's no longer an issue but I figured I'd ask...