Hi all,

I need to do my own version of phpMyAdmin for my php class. I encountered problem when trying modify existing data on database. I don't know what would be best way to modify whole table's data when I don't know exact amount of rows or columns. At this point I list existing table to <input type=text> and have also hidden inputs for delivering data to my updater php file. But what would be best way to actually update data to database. Do I just loop through all data and update it one by one or in a one big sql query or what? I don't want you guys to do this for me so no need for ready code, only the general idea.

Thanks in an advance.

Edit. Just realized I don't need that hidden input really for anything so that's gone but main problem still exists.

Member Avatar for diafol

You get the number of fields and number of records from the SQL query.
You create a table dynamically through php.

I would suggest some ajax / javascript in order to create an editable row - which places data of that record into textboxes / selects and adds an update button.

Also limit data retrieved with LIMIT clause to say 50 records and use pagelinks/pagination.

What about displaying, for example, no more than 50 records per page, so that a maximum of 50 rows will be updated at a time?

And then about updating a large amount of rows: each row contains data that is unique to that row, so you will probably have to run a query for each row. You modify a row by its primary key, which means each row will need to be updated separately. Except, of course, if changing the values of all rows at once.

I love this site. I always get great answers when I ask something. So thanks again. That limiting is good idea (how didn't I figure it out by myself). Now I probably can have one big dynamically created query or just loop all one by one either way it probably won't be too slow to execute. For javascript part I will definetely use that for data validation but the core functions need to be working on also on browsers which have JS disabled.

Member Avatar for diafol

Browsers with js disabled are few and far between these days, but, in the event of js not being available, you can fall back (degrade gracefully) to the old "edit" button next to a row, like the monstrous phpmyadmin, which would send you to an edit record page. The js-enabled browser would let you edit in-situ.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.