Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Small simple mysql record editor

Posted on 2008-06-16
10
Medium Priority
?
272 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
LVL 29

Accepted Solution

by:
rdivilbiss earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Suggested Courses

971 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