Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 16th, 2005, 07:18 AM
Registered User
Join Date: Nov 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Edit Form Query

Hi All,

I am still relatively new to PHP and MySQL but have been able to get quite a way with info available on the web.

OK ... I want to edit a record in my database using PHP. My main table (the one I want to edit) contains references to other tables. My original entry form dynamically queries the other tables and stores the id in the main table.

So the question now is how do I load an existing record in the edit form, default what was previously entered and show dynamically the other entries in the other table? Hope this makes sense?

e.g. for the main table I query the location table and retrieve the id, description and value fields (used later for calculations). The user selects the appropriate description and the database stores the id.

Thanks in advance for any help!

Reply With Quote
  #2 (permalink)  
Old November 18th, 2005, 04:27 AM
Friend of Wrox
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul

You're asking about relational db and normalization. In short, your tables are connected via IDs. A table typically has its own ID and other IDs that reference other tables.

In SQL, WHERE clause helps to join tables while querying ..
like WHERE tablename1.id = tablename2.id

If you're still confused, show us few lines of code. We also need know your db structure, to help you, specifically. By the way, MSQL AB (mysql.net) already provides free comprehensive documentation for all the explaination. We all are ourselves reading that.

Support Indian students' finances http://scholarship.mediasworks.com/
Reply With Quote
  #3 (permalink)  
Old November 18th, 2005, 08:59 AM
Registered User
Join Date: Nov 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks Anshul,

OK I have a table called "ops" and one of many tables called "agerisk". The agerisk table has an id field, description and value fields. I use the id field on the ops table to reference the appropriate row (id) in the "agerisk" table. The user is presented the description field in the combo box on the form. I have included some code from the original form below. I am struggling to understand how I can construct the same lookup to default what was entered by the user when they wish to edit/update the data.

          <select name=\"agerisk2\">
        <option value=\"\"></option>";

        for($i=0; $i<$ageriskNumber; $i++) {
            $ageriskAgeid = mysql_result($ageriskResult,$i,"agerisk.ageid");
            $ageriskDescription = mysql_result($ageriskResult,$i,"agerisk.Descriptio n");
            print " <option value=\"$ageriskAgeid\">$ageriskDescription</option>";


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit Table through a Form Coby Access VBA 3 August 17th, 2007 07:10 AM
Form view control, Authorized edit only nuttylife2 ASP.NET 2.0 Professional 0 July 10th, 2006 07:57 PM
2 tables, 1 query, 1 form, cannot edit :( tanjuakio Access 2 June 24th, 2005 06:24 AM
Edit form mrideout BOOK: Beginning ASP.NET 1.0 0 August 25th, 2004 04:32 PM
How form can edit mateenmohd VB Databases Basics 2 June 22nd, 2003 02:43 AM

All times are GMT -4. The time now is 08:09 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.