bao_jiffy wrote:Not sure that I followed all of the steps in this thread but I have to ask 3 questions. One for my benefit and another 2 hopefully for your benefit.
Would a query of select max(id) from `#__my_table` not get you the last inserted auto_increment value prior to your insert? You may have this all ready covered but I thought that I would ask any how.
No, that was the first iteration I tried. Here's why it won't work accurately: What if the most recent record was deleted, but the max pointer was still somewhere else. Let's say you had just added record #58. The next record obviously is going to be record #59, but if you deleted #58 and did as you say, check the highest record id for that table, it would return #57. You would think the next record was #58 but it would actually be #59 in the auto_increment value. I did this, and after deleting the most recent four records, my incrementing structure was four numbers off, which is why I had to figure out a way to query the table status for the auto_increment value.
bao_jiffy wrote:Also, I found that I had to through the ` quote marks around my table names to make them inherit the database prefix using the #_. Not sure if that helps your cause any but thought that I would put in my 2 cents there.
That seems to work with most queries, but would not work for the SHOW TABLE STATUS query.
bao_jiffy wrote:Now to MY question. Is there a simple example somewhere of reading a list of data into a simple form, edit a record or multiple records, then update the data without having to go through several php files? I am guessing that I just need to recall the same php when I complete my edits but I just can't seem to figure it out. I can create a basic form but if multiple records are returning, what is the proper way of editing a record and storing the results?
Thanks for any pointers, even if it is to a manual or sample component.
It's very easy to use the same PHP page to both display an empty form and then submit and save the data. Consider how Joomla does it all with one index.php! Your PHP page will have two (or more) "sections" what are controlled by access flags set in the form variables and accessed by IF-THEN statements or CASE statements. Consider the logic of:
Code: Select all
If (the page has no form values being submitted) {
Display the form code;
} else {
Save the form values being submitted;
}
Open up com_content.php and look at how it's done. The page's functions are accessed based on the value of $task. If the task is edit, do this function. If the task is copy, do this function. If the task is save, do this function.
Hopefully you will see the structure of how to use one PHP file to accomplish multiple tasks without getting confused by everything else around you.