I am working on a project of mine, where I want to get a table called 'Clients' from a database and display its data. All good, this was an easy task. Now I want to update some data in the table. I am trying to figure out which is the optimal way of doing this having in mind that I am working with Laravel framework.
I have the following for loop that I display the data in a .
for ($i=0; $i<$clientNumber; $i++) { ?>
<tr>
<td>
<form method="post" action="{{URL::to('/')}}">
{{csrf_field()}} <!-- Used for the token -->
<button type="submit" value="<?php echo $i; ?>" class="editButton" > <i class="fa fa-edit"></i> </button>
</form>
</td>
<td> <?php echo $data[$i]->clientId; ?> </td>
<td> <?php echo $data[$i]->clientFirstname; ?> </td>
<td> <?php echo $data[$i]->clientSurname; ?> </td>
<td> <?php echo $data[$i]->clientEmail; ?> </td>
<td> <?php echo $data[$i]->clientMobile; ?> </td>
<td> <?php echo $data[$i]->clientPhone; ?> </td>
<td> <?php echo $data[$i]->clientAdrress; ?> </td>
<td> <?php echo $data[$i]->companyName; ?> </td>
<td> <?php echo $data[$i]->companyType; ?> </td>
<td> <?php echo $data[$i]->services; ?> </td>
<td> <?php echo $data[$i]->websiteURL; ?> </td>
<td> <?php echo $data[$i]->renewDate; ?> </td>
<td> <?php echo $data[$i]->totalPrice; ?> </td>
<td> <?php echo $data[$i]->deposit; ?> </td>
<td> <?php echo $data[$i]->balance; ?> </td>
<td> <?php echo $data[$i]->serverPrice; ?> </td>
<td> <?php echo $data[$i]->comments; ?> </td>
<input type="hidden" name="rowId" value="<?php echo $i; ?>">
</tr>
<?php
}
As you can see I have added the following code
<button type="submit" value="<?php echo $i; ?>" class="editButton" > <i class="fa fa-edit"></i> </button>
so that I can have a button for each row and when I click that I will be prompted to an edit area.
I would like to solve this without loading another page. For example I already developed a version with a <form> that when the button is clicked I am redirected to the new page.
I am struggling because I don't know how to form an SQL query in Laravel that depend on the row number (which will be known after a button or something similar is pressed). For example SELECT * FROM table WHERE id==XXX.
Is the problem clear enough?
Thanks for your time, -Vasilis