PHP Cycle Through MySQL Table With Submit Button

Okay, I've looked for a solution to this question, but to no avail. It could be the way I worded it, but I've tried almost everything I could think of. And I know this is probably something so simple, I just can't wrap my head around it.

The problem I'm having is this:

I have a form that is prepopulated with data from a MySQL database. This part of the form is strictly for viewing the records (that were previously entered by the user). I can get it to work; I have the database linked, and it shows the data for the row of the particular table that I want. But this is what I'm having trouble with.

I want there to be a button that the user can press that cycles through each row of data in the database, and outputs it in the form accordingly.

It's a little complicated, so I'll use a simple example.

Let's say I have a basic table in a MySQL database with three columns: ID, Name, and EmailAddress.

Here's the query that grabs the data:

$sql = "SELECT * from tbl_Users ORDER BY ID ASC";
$query = mysql_query($sql);
$result = mysql_fetch_array($query);

Now I know this is deprecated, but I am working in an older version of php, and I'm trying to stay consistent other pages/apps in this particular domain.

Now let's say I have a simple form with two inputs and a submit button.

HTML

<form name="button" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="Name" value="<?php echo $row[Name]; ?>" />
<input type="text" name="emailAddress" value="<?php echo $row[EmailAddress]; ?>" />
<input type="submit" name="submit" value="Next Record" />
</form>

Now I can get it to echo what I need in the form. It can prepopulate the form with a row, as I want it to. The trouble lies with the submit button.

When the submit button is clicked, I want the next row to populate in the form, and so on until the end of the records.

I've tried the if(isset($_POST['submit']{...}, yet I don't know exactly to get this to work. I've tried loops, etc. I know there is a way, I just cannot comprehend one right now. Thanks in advanced.

Answers


Okay, so I DID manage to get it to work with PHP. I found a simple PHP Pagination script and changed the limit of the query to 1. Instead of echoing out the results of the query in the WHILE loop, I just called the variables for the form


Need Your Help

document.onkeyup only when not typing in textbox

php javascript html

I'm trying to make a navigation system using document.onkeyup where pressing left arrow on the keyboard forwards the user to the previous ID and the same with the right arrow forwarding to the next...