tags:

views:

291

answers:

2

I currently have a PHP form that uses AJAX to connect to MySQL and display records matching a user's selection (http://stackoverflow.com/questions/2593317/ajax-display-mysql-data-with-value-from-multiple-select-boxes)

As well as displaying the data, I also place an 'Edit' button next to each result which displays a form where the data can be edited. My problem is editing unique records since currently I only use the selected values for 'name' and 'age' to find the record. If two (or more) records share the same name and age, I am only able to edit the first result.

A: 

Let's assume your file for editing is edit.php. Then, in the file where you generate the edit links, try changing your edit button link as follows:

'<a href="edit.php?id="'.$row['ID'].'">edit</a>'

Then you will be able to access ID variable as

echo $_REQUEST['ID'];

Note that the ID is case sensitive. Let me know how it goes.

pinaki
Is there anyway to do this without a separate edit.php? My 'edt' function is in index.php and the links are generated in getPages.php. I tried $_SERVER['PHP_SELF'] but it didnt run the function nor append the id to the url
Robert
Also, my index.php file runs the 'edit' function on $_POST['edit'] which breaks if I use a hyperlink instead
Robert
A: 

when displaying records from ajax, also send the primary field(id in most cases) along with name and age

and when u are displaying these data along with edit incorporate that primary field with edit

nik
I have set the id of each edit button to the ID of the record diplayed in the same row. I can't get access to it though
Robert
ok if u r sure u have retrieve id correctly then u can do 2 things1) if working in forms: Have a hidden field in the form. and set the id in its value field just like u did with editlike:<input type="hidden" name="myId" value="whatever the id is">then on submitting u can retrieve the id by $_REQUEST['myId']2. if without form then u can use javascript on edit button Like:<input type="button" name="editID" value="Edit" onclick="location.href='editthis.php?myId=whatever the id is'">and can retrieve like $_GET['myId'];
nik