Selecting Records after output (PHP Oriented)

I’m not sure whether this is more qualified in the PHP section or the MySQL section but I kind of want to hear what SQL people have to say first.

I want the user to be able to select a specific record after it has been rendered to edit it. For example

Consider the following html/php document


  <?php while($contact_result_row = mysql_fetch_array($contact_result, MYSQL_BOTH)){ ?>
	<td> <?php echo $contact_result_row['FirstName']; ?> </td>
	<td> <?php echo $contact_result_row['LastName']; ?> </td>
	<td> <?php echo $contact_result_row['Phone']; ?> </td>
	<td> <?php echo $contact_result_row['EmailAddress']; ?> </td>
  <?php  } ?>

This simply displays a table of all the data within a query.
So let say I wanted to select the third record from the table maybe I could add a button to edit each record for each row.
My question is, once the user clicks this button how does the program know which record to jump to.

Do I make a variable array where each time the while loop initiates it saves the row id into a variable called $contact[$i]? Or what other methods could I use because I have one big query, and then two sub queries on the same page to display data for each individual row of the first query.

(Kind of like a subform within a form like in MSAccess)

Thank you for replies.

I assume you are aware that AJAX is javascript.

AJAX is not a different language. It is just a particular technique in using javascript.

Interesting choice of phrase, what would you describe as a ‘creative’ solution?

Another option is to add an edit button next to each user record in the html table.

The edit button has an onclick even handler which points to a url with a query string attached containing the userID (from the database) for that user.

The url points to a web page containing a form with inputs to edit the database table the original user data came from.

The inputs in the form are then updated as required and submitted to a server side script to update the database record for that userID.

I guess this is the best answer, I was hoping for something more creative:

You can achieve this only using PHP but it is going to make for a very static and unfriendly user experience. The best solution would be to use JavaScript in addition to PHP to support a persistent interface for modifying the data.

Lol yes I did know. It’s funny actually I am afraid of javascript because I don’t want to write code that can be altered to do things I don’t want it to do. And today our ad server (which uses javascript) just got hacked and is serving malware :frowning: [don’t worry i am not deterred me from learning it]

Very good comments,

@AnthonySterling by creative solutions, I guess I would say a modular design would be creative, nothing like calling a chunk of code repeatedly and getting different results based on results.

@oddz I was hoping to avoid javascript for now and make version 2.0 AJAX (after I learn it…) Javascript is not my forte
albeit though
@Kalon solutions seems to be a good temporary solution, despite my anxiety about javascript.