Solved

Small simple mysql record editor

Posted on 2008-06-16
10
258 Views
Last Modified: 2010-04-21
I have php code that connects to a MySQL database and grabs all the records I need. It then displays those records (one record per line - just text) on browser page. What I would like to do is add an edit button and a print button at the end of each of those records (note: the amount or records could vary from 30 to 200 any month). When the edit button is clicked, it opens a HTML Form, populates it with the data in that single record and only allows the user change a few things, when they are done making the needed changes, they click a save button which updates the MySQL database, and display the list of records again. If they click the print button - it display another html page and formats the record for printing, with another print button, when the print button is clicked, the page is set to a printer, and the original record list is displayed again.

I am not trying to ask that someone else code this (although if the wheel is already out there and offered I certainly would not ignore it!), just the best approach to take. I am familiar with PHP & HTML Forms, have never dove into JScript, or any of the other methods I might be able to use. All inputs are greatly appreciated.
I have tried using phpMyAdmin, and sidu - and the biggest problem I see with them is they have too much functionality for what I was hoping for.
 
0
Comment
Question by:NTNBower
  • 5
  • 5
10 Comments
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 21794600
Is your current display in a table or really just one line of text?
0
 

Author Comment

by:NTNBower
ID: 21794752
I use a php page, and it connects to the database, query's the database and then dumps the results in php variable, then I loop through the variable and display 1 record per line, so it looks like:

FPO#: 123 Part#: 456 DueDate: 060608 NeedRoll: N NeedRace: N NeedRetain: N
FPO#: 456 Part#: 789 DueDate: 060608 NeedRoll: Y NeedRace: N NeedRetain: N
...

and that is whats displayed on the web page returned by the PHP code. I would like to add buttons to the end of each record, one button for Edit & one for Print - like:

FPO#: 123 Part#: 456 DueDate: 060608 NeedRoll: N NeedRace: N NeedRetain: N [Edit] [Print]
FPO#: 456 Part#: 789 DueDate: 060608 NeedRoll: Y NeedRace: N NeedRetain: N [Edit] [Print]
...

Clicking edit or print would open (goto) another page, I am thinking for edit I could just use a form to let them make their changes to NeedRoll, NeedRace, NeedRetain (boolean either yes or no) then it would connect to the MySql and submit their toggle changes to the MySQL database, and re-open the original list again (should be able to see their changes. As for the print button - it just opens (goes to)  a windows displaying the text in a report format for them to print out.

I could put the output into a table, but so far I just have text being echoed out.  
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 21794923
No need for a table other than it might be neater.

Essentially you need the record's unique id for your button...

<input type="button" value="Edit" onclick="edit(record-id);">

Since you just wrote plain text, you'll need to call back and look up that record before you can edit, the call back (post) to update the info.  That's doable and is a better method if the is a likelihood of two people working on the same record at once.

Another method would be to write the data to the browser in a way you could directly gather the details needed to be editted, either as a JavaScript array or as part of the DOM (say a table) so you do not have to query again to get the record to edit.

With either method you'll need a new page that receives the posted data and updates the record.

Is JavaScript available?

0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 21795729
0
 

Author Comment

by:NTNBower
ID: 21797540
I have never used JScript - while it looks very nice, I am just not familiar with it. I actually thought I would just loop through pages as needed, like show entire list of records with the edit buttons, if you click edit for that record - the whole page changes to the edit page for just that record (using the key to do another query to mysql, and display the editor page). when your done editing, clicking save would submit the MySQL changes, and reload (or call) the original php page again that should now show the changes. Just continueing like this for each record they need to change.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 29

Accepted Solution

by:
rdivilbiss earned 250 total points
ID: 21797905
Then you should use a hyperlink, rather than a button.

e.g. <a href="edit.php?id=123">edit</a>

And on the edit page, after a successful edit set the header location to the original page.
0
 

Author Comment

by:NTNBower
ID: 21802175
What can I say - so many times you just cannot see the forest for the trees. Brilliant - thanks!
0
 

Author Closing Comment

by:NTNBower
ID: 31467592
Perfect - for me, I try and prove the concept - then the developers take it and make it pretty. This is going to work out just fine. Thanks again.
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 21804414
I liked my fancy edit in place better ;-)
0
 

Author Comment

by:NTNBower
ID: 21804665
So did I - however - liking and implementing are two very different things -) In the 10 minutes it took me to do the HTML solution - I don't think it could be beat. I am sure once the real developers get their hands on it - it will be Jscripted and prettified much more than my kiss (proof of concept) approach.

Thanks a ton.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now