0

I have a table that is working perfectly fine, however, it currently sends the user to a phpmyedit screen no matter which edit link is clicked. What I want to accomplish is clicking the inline link to directly edit that particular row or 'id'. Here is an example of my code:

$result = mysqli_query($con,"SELECT * FROM `TABLE_NAME` ORDER BY ID DESC");
echo "<table>";
echo "<table border='1' style='margin:200px 200px 500px 50px;'>
<tr>
<th>ID</th>
<th>TABLE HEADER</th>
<th>TABLE HEADER</th>
<th>TABLE HEADER</th>
<th>TABLE HEADER</th>
<th>TABLE HEADER</th>
<th>TABLE HEADER</th>
<th>TABLE HEADER</th>
<th>TABLE HEADER</th>
<th>Edit</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['ID'] . "</td>";
  echo "<td>" . $row['rowName'] . "</td>";
  echo "<td>" . $row['rowName'] . "</td>";
  echo "<td>" . $row['rowName'] . "</td>";
  echo "<td>" . $row['rowName'] . "</td>";
  echo "<td>" . $row['rowName'] . "</td>";
  echo "<td>" . $row['rowName'] . "</td>";
  echo "<td>" . $row['rowName'] . "</td>";
  echo "<td>" . $row['rowName'] . "</td>";
  echo "<td><a href='http://phpmyedit.com/editexample".$row['']."'>Edit</a></td><tr>";
  echo "</tr>";
  }
echo "</table>";

?>

So basically I just need to allow the edit link to directly edit that id in the row it was clicked in.

**EDIT: I'm using PHPMyEdit to edit/update the data in the database table, and would like to continue using PHPMyEdit.

Thanks in advance.

1
  • You're going to need some JavaScript. Commented Nov 18, 2014 at 20:02

2 Answers 2

2
echo "<td><a href='edit.php?id=".$row['ID']."'>Edit</a></td><tr>";

In edit.php you have to create form which values will be loaded from database:

<?php 

if (isset($_POST['fieldName']){
  mysqli_query($con, 'UPDATE `TABLE_NAME` SET fieldName='.$_POST['fieldName'].' WHERE ID='.intval($_GET['id']);
  exit;
}

$row = mysqli_fetch_assoc(mysqli_query($con, 'SELECT * FROM `TABLE_NAME` WHERE ID='.intval($_GET['id']))); ?>
<form method="POST">
<input type="text" name="fieldName" value="<?php echo $row['fieldName'] ?>">
<!--    -->
<input type="submit" value="save edit">
</form>

You need improve this pseudocode with data filtering, add more fields, include db connection etc.

Sign up to request clarification or add additional context in comments.

2 Comments

@Foxbound The PHPMyEdit system has the edit portion. I am curious if I can use that instead of creating a brand new form that pulls values from the database.
Sorry then. I can't analyze phpmyedit code on phone to help you.
0

I think you need a javascript code to trigger Edit mode.

But first, you need to give your table fields unique IDs while executing the while loop.

$counter=1;
while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><div id='ID_$counter'>" . $row['ID'] . "</div></td>";
  echo "<td><div id='TH1_$counter'>" . $row['rowName'] . "</div></td>";
  echo "<td><div id='TH2_$counter'>" . $row['rowName'] . "</div></td>";
...
  echo "<td><button onclick='triggerEdit($counter)'>Edit this row</button></td><tr>";

$counter++;
}

then using javascript create the edit and update functions:

    function triggerEdit(rowNumber) {
            document.getElementById('id_'+rowNumber).innerHTML = "<input type=text id='SOMEIDx'><button onclick='update(SOME_IDx)'>update</button>";
            document.getElementById('TH1_'+rowNumber).innerHTML = "<input type=text id='SOMEIDx2'><button onclick='update(SOME_IDx2)'>update</button>";
// don't forget to assign the IDs
        }

If you want the old values, you can access them using document.getElementById().innerHTML before you change them.

Finally, Construct an update function that sends the data using AJAX, given the ID of the field.

1 Comment

I'm trying to keep it in PHPMyEdit so I don't have to take a lot of time to use JavaScript. The code from Foxbound worked in a way by adding the ?ID in the edit.php - it recognizes the id of the particular row, however it still just takes it to the main table page of phpmyedit. Any thoughts on that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.