Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 07-29-2006, 07:58 AM   #1 (permalink)
dmavdm
Registered User
 
Join Date: Jul 2006
Posts: 2
dmavdm is on a distinguished road
creating a link between db output and editing

I'm a newbie so I may just be approaching this all wrong.

I have a db from which I retrieve a table of results and present this on via an html form generated with php. My first column for each row has an image that the user can click on to bring up a new pop up form in which they can edit that row of data and then submit to post the changes to the db.

How do I assign a key from database (for that record) which will allow me to retrieve the appropriate record for editing in my pop up form? In otherwords, when the user click on the row they want to edit, I need to know which record that corresponds to so I can show them only that record in the edit form.

Thanks.
dmavdm is offline   Reply With Quote
Old 07-29-2006, 08:29 AM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 672
DJMaze is on a distinguished road
Your db table records need a key/id field for easy access.

MySQL: AUTO_INCREMENT
PostgreSQL: SERIAL or see below
Relational SQL: 'before insert' trigger that calls the gen_id() procedure with the appropiate generator.
DJMaze is offline   Reply With Quote
Old 07-29-2006, 09:51 AM   #3 (permalink)
dmavdm
Registered User
 
Join Date: Jul 2006
Posts: 2
dmavdm is on a distinguished road
Thanks DJ, I've got that part taken care of. My question is really more about how to code my page to that when the user clicks on a row in my form, I know which record (i.e. the key_id) they selected. I think I somehow need to embed the key_id in the object they click on.

Maybe a little more detail will help... I have a query that returns a set of records. Then i'm looping through the returned array and generating the html form for each record, including columns for the fields in my database plus the "click here to edit" icon that i'm putting at in the first column of the form.

So if i return 10 records from query (i.e. 10 rows of data in my html table/form), how do i know which row the user clicks on so i can return the appropriate record in a new form for editing? This is probably very basic, but I'm not seeing it.

Thanks
dmavdm is offline   Reply With Quote
Old 07-29-2006, 11:35 AM   #4 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
I imagine the popup function is some sort of javascript function, so when you're generating the images/onclick code, just put the database row id in as an additional parameter of the javascript function. Then you can do an SQL 'UPDATE something = newthing IN table WHERE ID = id'
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 09:04 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting